<?php
class InventoryController extends Ovis_Controller {

	private $_menuName = 'Inventory';

	public function init()
	{
		parent::init();
		$this->checkInstance();
	}

	public function loginAction()
	{
		$this->_redirect('/user/login');
	}

	public function indexAction()
	{
		$userInformation = Ovis_Controller::getLoggedUser();
		if ($userInformation['accounttype'] == Sss_Ultility_Setting::ACCOUNT_OVIS || $userInformation['accounttype'] == Sss_Ultility_Setting::ACCOUNT_CUSTOMER) {
			$this->_redirect("/inventory/hardware");
		} else {
			$this->_redirect("/inventory/vendor");
		}
	}

	public function vendorAction()
	{
		$userInformation = Ovis_Controller::getLoggedUser();
		if($userInformation['accounttype'] == Sss_Ultility_Setting::ACCOUNT_CUSTOMER) {
			$this->_redirect('/user/login');
		}
		//call table vendor MVC mappers
		$vendorGateway    = new Application_Model_Mapper_Vendor();
		$get  = $this->getRequest()->getParams();
		$isSearch = isset($get['s']) && $get['s'] == 1;
		//get order, page, limit param
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD] = isset($get[Sss_Ultility_CommonViewParamater::ORDERFIELD]) ? $get[Sss_Ultility_CommonViewParamater::ORDERFIELD] : null;
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE]  = isset($get[Sss_Ultility_CommonViewParamater::ORDERTYPE]) ? $get[Sss_Ultility_CommonViewParamater::ORDERTYPE] : null;
		$filterParam[Sss_Ultility_CommonViewParamater::PAGE] = isset($get[Sss_Ultility_CommonViewParamater::PAGE]) ? $get[Sss_Ultility_CommonViewParamater::PAGE] : 1;

		//test param filter: omit title text in field
		$paramName        = $isSearch ? strcmp($this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'vendorname', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('VENDOR_NAME')) == 0 ? '' : $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'vendorname', Sss_Ultility_CommonViewParamater::UNDERFINE) : '';
		$paramContact     = $isSearch ? strcmp($this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'contact', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('VENDOR_CONTACT')) == 0 ? '' : $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'contact', Sss_Ultility_CommonViewParamater::UNDERFINE) : '';
		$paramSaleContact = $isSearch ? strcmp($this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'sale_contact', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('VENDOR_SALE_CONTACT')) == 0 ? '' : $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'sale_contact', Sss_Ultility_CommonViewParamater::UNDERFINE) : '';



		$filterParam['vendorname']         = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'vendorname', trim($paramName), Sss_Ultility_SessionName::VENDOR_SESSION);
		$filterParam['contact']      = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'contact', trim($paramContact), Sss_Ultility_SessionName::VENDOR_SESSION);
		$filterParam['sale_contact'] = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'sale_contact', trim($paramSaleContact), Sss_Ultility_SessionName::VENDOR_SESSION);

		if ($userInformation && $userInformation['accounttype'] == Sss_Ultility_Setting::ACCOUNT_OVIS) {
			//delete vendor
			$vendorId = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::DELETE_ID, -1);
			if (isset($vendorId) && $vendorId != -1) {
				$deleteId    = $vendorGateway->deleteRow($vendorId);
				if (isset($deleteId)) {
					$this->view->assign(Sss_Ultility_CommonViewParamater::NOTICEMSG, Resources::_('DELETE_VENDOR_SUCCESSFULL'));
				} else {
					$this->view->assign(Sss_Ultility_CommonViewParamater::NOTICEMSG, Resources::_('DELETE_VENDOR_FAIL'));
				}
			}
		}
		//get Vendor list
		$list       = $vendorGateway->getVendorList($this->view->limit, 0, $filterParam);
		$row        = $list->list;
		$pagination = $list->pagination;
		$this->view->assign(Sss_Ultility_CommonViewParamater::FILTER_PARAM, $filterParam);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW, $row);
		$this->view->assign(Sss_Ultility_CommonViewParamater::PAGINATION, $pagination);

		$orderQueryString = '';
		if ($isSearch) {
			$orderQueryString = '&' . Sss_Ultility_CommonViewParamater::PAGE . '=' . $filterParam[Sss_Ultility_CommonViewParamater::PAGE] . '&s=1';
		} else {
			$orderQueryString = '&' . Sss_Ultility_CommonViewParamater::PAGE . '=' . $filterParam[Sss_Ultility_CommonViewParamater::PAGE];
		}
		$queryString = '';
		if ($isSearch) {
			$queryString .= '&s=1';
		}
		if (!is_null($filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD])) {
			$queryString .= '&' . Sss_Ultility_CommonViewParamater::ORDERFIELD . '=' . $filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD];
		}
		if (!is_null($filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE])) {
			$queryString .= '&' . Sss_Ultility_CommonViewParamater::ORDERTYPE . '=' . $filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE];
		}
		$this->view->assign(Sss_Ultility_CommonViewParamater::QUERY_STRING, $queryString);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ORDER_QUERY_STRING, $orderQueryString);
		//action button
		if($userInformation['accounttype'] == Sss_Ultility_Setting::ACCOUNT_OVIS) {
			$actionbuttons = array(
			new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::ADD, 'add-vendor', Resources::_('ADD_NEW_VENDOR')),
			new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::EXPORT, 'vendor-export?export=1', Resources::_('EXPORT')),
			new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::PRINTF, 'vendor-export?print=1', Resources::_('PRINT')),
			new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::SEARCH, 'javascript:hideShow(this);', Resources::_('SEARCH'))
			);
		} else {
			$actionbuttons = array(
			new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::EXPORT, 'vendor-export?export=1', Resources::_('EXPORT')),
			new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::PRINTF, 'vendor-export?print=1', Resources::_('PRINT')),
			new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::SEARCH, 'javascript:hideShow(this);', Resources::_('SEARCH'))
			);
		}
		$this->view->assign(Sss_Ultility_CommonViewParamater::ACTION_BUTTONS, $actionbuttons);
		//get breadscrumb
		$breadscrumbs = array(
		new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
		new Sss_CommonEntity_BreadScrumb(Resources::_('VENDORS'), '#')
		);
		$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
	}

	public function vendorExportAction()
	{
		$userInformation = Ovis_Controller::getLoggedUser();
		if ($userInformation['accounttype'] == Sss_Ultility_Setting::ACCOUNT_CUSTOMER) {
			$this->_redirect('/user/login');
		}
		$vendorTable = new Application_Model_Mapper_Vendor();
		//get order, page, limit param
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD] = isset($get[Sss_Ultility_CommonViewParamater::ORDERFIELD]) ? $get[Sss_Ultility_CommonViewParamater::ORDERFIELD] : null;
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE] = isset($get[Sss_Ultility_CommonViewParamater::ORDERTYPE]) ? $get[Sss_Ultility_CommonViewParamater::ORDERTYPE] : null;
		$filterParam[Sss_Ultility_CommonViewParamater::PAGE] = isset($get[Sss_Ultility_CommonViewParamater::PAGE]) ? $get[Sss_Ultility_CommonViewParamater::PAGE] : 1;

		//test param filter: omit title text in field
		$paramName = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'vendorname', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$paramContact = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'contact', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$paramSaleContact = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'sale_contact', Sss_Ultility_CommonViewParamater::UNDERFINE);

		$filterParam['vendorname'] = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'vendorname', $paramName, Sss_Ultility_SessionName::VENDOR_SESSION);
		$filterParam['contact'] = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'contact', $paramContact, Sss_Ultility_SessionName::VENDOR_SESSION);
		$filterParam['sale_contact'] = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'sale_contact', $paramSaleContact, Sss_Ultility_SessionName::VENDOR_SESSION);


		//get Vendor list
		$list = $vendorTable->getVendorList(-1, 0, $filterParam);
		$rowAll = $list->list;
		$pagination = $list->pagination;
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW, $rowAll);
		$this->view->assign(Sss_Ultility_CommonViewParamater::PAGINATION, $pagination);
		$count = ((($pagination->pagecurrent * Sss_Ultility_Setting::PAGE_SIZE) - Sss_Ultility_Setting::PAGE_SIZE));
		$columnNames = array(
			Resources::_('ID'),
			Resources::_('NAME'),
			Resources::_('VENDOR_CONTACT'),
			Resources::_('VENDOR_WEBSITE'),
			Resources::_('VENDOR_EMAIL'),
			Resources::_('VENDOR_SALE_CONTACT'),
			Resources::_('VENDOR_SALE_EMAIL'),
			Resources::_('VENDOR_PHONE'),
			Resources::_('VENDOR_OF_ITEMS')
		);

		$arrData = array();
		$index = 0;
		foreach ((array) $rowAll as $row) {
			$count++;
			$arrData[$index][] = $count;
			$arrData[$index][] = $row['vendorname'];
			$arrData[$index][] = $row['contact'];
			$arrData[$index][] = $row['website'];
			$arrData[$index][] = $row['email'];
			$arrData[$index][] = $row['sale_contact'];
			$arrData[$index][] = $row['sale_email'];
			$arrData[$index][] = $row['phone'];
			$arrData[$index][] = is_null($row['hardwarenumber']) ? 0 : $row['hardwarenumber'];
			$index++;
		}
		if (isset($_GET['export'])) {
			$this->exportDataToExcel($columnNames, $arrData, Resources::_('VENDORS'));
		}
	}

	public function geomappingAction()
	{
		//get breadscrumb
		$breadscrumbs = array(
			new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
			new Sss_CommonEntity_BreadScrumb('Geomapping', '#')
		);
		$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
		$paramVendorId = $this->_request->getParam('vendorid', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$paramStockLocationId = $this->_request->getParam('stocklocationid', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$paramHardwareId = $this->_request->getParam('hardwareid', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$paramStockLocationId = $this->_request->getParam('stocklocationid', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$actionName = 'index';
		if ($paramVendorId != Sss_Ultility_CommonViewParamater::UNDERFINE) {
			$actionName = 'vendor';
			//get address to show on map
			$vendorTable = new Application_Model_Mapper_Vendor();
			$dataVendorById = $vendorTable->getVendorById($paramVendorId);
			$s = "var markers =[";
			$s .= "{";
			$s .= "'vendorname':'" . $dataVendorById->vendorname . "',";
			$s .= "'address':'" . $dataVendorById->address . "',";
			$s .= "'website':'" . $dataVendorById->website . "',";
			$s .= "'created_date':'" . date(DATETIMEFORMAT, $dataVendorById->created_date) . "',";
			$s .= "'updated_date':'" . ($dataVendorById->updated_date > 0 ? date(DATETIMEFORMAT, $dataVendorById->updated_date) : '0') . "'";
			$s .= "},";
			$s .= "];";
		} elseif ($paramHardwareId != Sss_Ultility_CommonViewParamater::UNDERFINE) {
			$actionName = 'hardware';
			//get address to show on map
			$hardwareTable = new Application_Model_Mapper_Hardware();
			$dataHardwareById = $hardwareTable->getHardwareById($paramHardwareId, 1);
			$s = "var markers =[";
			$s .= "{";
			$s .= "'hardwarename':'" . $dataHardwareById->hardwarename . "',";
			$s .= "'address':'" . $dataHardwareById->address . "',";
			$s .= "'buyer':'" . $dataHardwareById->buyer . "',";
			$s .= "'created_date':'" . date(DATETIMEFORMAT, $dataHardwareById->created_date) . "',";
			$s .= "'updated_date':'" . ($dataHardwareById->updated_date > 0 ? date(DATETIMEFORMAT, $dataHardwareById->updated_date) : '0') . "'";
			$s .= "},";
			$s .= "];";
		} elseif ($paramStockLocationId != Sss_Ultility_CommonViewParamater::UNDERFINE) {
			$actionName = 'stock-locations';
			//get address show on map        
			$stockLocationTable = Sss_Service_Locator::getInstance()->getService($this->_getOvisTable('StockLocation'));
			$dataStockLocationById = $stockLocationTable->select($paramStockLocationId);

			$s = "var markers =[";
			$s .= "{";
			$s .= "'stocklocationname':'" . $dataStockLocationById->stocklocationname . "',";
			$s .= "'address':'" . $dataStockLocationById->address . "',";
			$s .= "'created_date':'" . date(DATETIMEFORMAT, $dataStockLocationById->created_date) . "',";
			$s .= "'updated_date':'" . ($dataStockLocationById->updated_date > 0 ? date(DATETIMEFORMAT, $dataStockLocationById->updated_date) : '0') . "'";
			$s .= "},";
			$s .= "];";
		} else {
			$s = "var markers ='';";
		}

		//action button
		$actionbuttons = array(
			new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::BACK, $actionName, Resources::_('BTN_BACK'))
		);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ACTION_BUTTONS, $actionbuttons);
		$this->view->assign("s", $s);
		$this->view->assign('vendorid', $paramVendorId);
		$this->view->assign('hardwareid', $paramHardwareId);
		$this->view->assign('stocklocationid', $paramStockLocationId);
	}

	public function addVendorAction()
	{
		$userInformation = Ovis_Controller::getLoggedUser();
		if($userInformation['accounttype'] != Sss_Ultility_Setting::ACCOUNT_OVIS) {
			$this->_redirect('/user/login');
		}
		if($userInformation['accounttype'] == Sss_Ultility_Setting::ACCOUNT_OVIS)
		{
			//insert vendor
			$params = $this->_request->getParams();
			if (isset($params[Sss_Ultility_CommonViewParamater::BTN_SAVE])) {
				if ($userInformation) {
					$createBy   = $userInformation['accountid'];
					$createDate = Sss_Ultility_Common::getDateTimeNumber();
					// Process adding new vendor
					$vendorGateway = new Application_Model_Mapper_Vendor();
					$vendor        = new Application_Model_Vendor();
					$vendor->setVendorName(addslashes($params['vendorname']));
					$vendor->setContact(addslashes($params['contact']));
					$vendor->setWebsite(addslashes($params['website']));
					$vendor->setEmail(addslashes($params['email']));
					$vendor->setSaleContact(addslashes($params['sale_contact']));
					$vendor->setSaleEmail(addslashes($params['sale_email']));
					$vendor->setPhone(addslashes($params['phone']));
					$vendor->setAddress(addslashes($params['address']));
					$vendor->setCreatedBy($createBy);
					$vendor->setCreatedDate($createDate);
					$vendor->setUpdatedBy($createBy);
					$vendor->setUpdatedDate($createDate);
					$vendor->setIsused(0);
					$vendorId    = $vendorGateway->save($vendor);
					if (isset($vendorId)) {
						$this->redirect(Resources::_('ADD_VENDOR_SUCCESSFULL'), $this->view->url(array(
						Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
						Sss_Ultility_CommonViewParamater::ACTION => 'vendor'
						)));
					} else {
						$this->redirect(Resources::_('ADD_VENDOR_FAIL'), $this->view->url(array(
						Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
						Sss_Ultility_CommonViewParamater::ACTION => 'vendor'
						)));
					}
				}
			}

			//get breadscrumb
			$breadscrumbs = array(
				new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
				new Sss_CommonEntity_BreadScrumb(Resources::_('VENDORS'), 'index'),
				new Sss_CommonEntity_BreadScrumb(Resources::_('ADD_NEW_VENDOR'), '#')
			);
			$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
		}
	}

	public function editVendorAction()
	{
		$userInformation = Ovis_Controller::getLoggedUser();
		if($userInformation['accounttype'] == Sss_Ultility_Setting::ACCOUNT_OVIS || $userInformation['accounttype'] == Sss_Ultility_Setting::ACCOUNT_VENDOR) {
			$vendorTable = new Application_Model_Mapper_Vendor();
			$hardwareTable = new Application_Model_Mapper_Hardware();
			$vendorAccountTable = new Application_Model_Mapper_VendorAccount();
			$params = $this->_request->getParams();
			$vendorId = $this->getRequest()->getParam('vendorid', -1);

			$this->view->assign('vendorid', $vendorId);

			//get stock location by id
			$vendor  = $vendorTable->getVendorById($vendorId);
			$vendorAccounts = $vendorAccountTable->getAccountByVendorId($vendorId);
			$arrVendorAccount = array();
			foreach($vendorAccounts as $v) {
				$arrVendorAccount[] = $v['account'];
			}
			if (!in_array($userInformation['accountid'], $arrVendorAccount)) {
				if($userInformation['accounttype'] != Sss_Ultility_Setting::ACCOUNT_OVIS) {
					$this->_redirect('/user/login');
					return;
				}
			}
			$this->view->assign(Sss_Ultility_CommonViewParamater::VENDOR, $vendor);
			$countitems = $hardwareTable->countHardwareAssignTo($vendorId);
			$this->view->assign('countitems', $countitems);
			//update vendor
			if (isset($params[Sss_Ultility_CommonViewParamater::BTN_SAVE])) {
				$userInformation = Ovis_Controller::getLoggedUser();
				if ($userInformation) {
					$updateBy    = $userInformation['accountid'];
					$updateDate  = Sss_Ultility_Common::getDateTimeNumber();
					// Process update vendor
					$vendor = $vendorTable->findById($vendorId);
					$vendor->setVendorName(addslashes($params['vendorname']));
					$vendor->setContact(addslashes($params['contact']));
					$vendor->setWebsite(addslashes($params['website']));
					$vendor->setEmail(addslashes($params['email']));
					$vendor->setSaleContact(addslashes($params['sale_contact']));
					$vendor->setSaleEmail(addslashes($params['sale_email']));
					$vendor->setPhone(addslashes($params['phone']));
					$vendor->setAddress(addslashes($params['address']));
					$vendor->setUpdatedBy($updateBy);
					$vendor->setUpdatedDate($updateDate);
					$vendorId    = $vendorTable->save($vendor);
					if (isset($vendorId)) {
						$this->redirect(Resources::_('EDIT_VENDOR_SUCCESSFULL'), $this->view->url(array(
						Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
						Sss_Ultility_CommonViewParamater::ACTION => 'vendor'
						)));
						return;
					} else {
						$this->redirect(Resources::_('EDIT_VENDOR_FAIL'), $this->view->url(array(
						Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
						Sss_Ultility_CommonViewParamater::ACTION => 'vendor'
						)));
						return;
					}
				}
			}
			//get breadscrumb
			$breadscrumbs = array(
				new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
				new Sss_CommonEntity_BreadScrumb(Resources::_('VENDORS'), 'index'),
				new Sss_CommonEntity_BreadScrumb(Resources::_('EDIT_VENDOR'), '#')
			);
			$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
		}
	}

	public function vendorAccountSearchAction()
	{
		$accountsTable = Sss_Service_Locator::getInstance()->getService($this->_getOvisTable('Account'));
		//get order, page, limit param
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD] = $this->getValueRequest(Sss_Ultility_CommonViewParamater::ORDERFIELD, $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::ORDERFIELD, Sss_Ultility_CommonViewParamater::UNDERFINE), Sss_Ultility_SessionName::VENDOR_ACCOUNT_SEARCH_SESSION);
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE] = $this->getValueRequest(Sss_Ultility_CommonViewParamater::ORDERTYPE, $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::ORDERTYPE, Sss_Ultility_CommonViewParamater::UNDERFINE), Sss_Ultility_SessionName::VENDOR_ACCOUNT_SEARCH_SESSION);
		$filterParam[Sss_Ultility_CommonViewParamater::PAGE] = $this->getValueRequest(Sss_Ultility_CommonViewParamater::PAGE, $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::PAGE, Sss_Ultility_CommonViewParamater::UNDERFINE), Sss_Ultility_SessionName::VENDOR_ACCOUNT_SEARCH_SESSION);
		$limit = $this->getValueRequest(Sss_Ultility_CommonViewParamater::LIMIT, $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::LIMIT, Sss_Ultility_CommonViewParamater::UNDERFINE), Sss_Ultility_SessionName::VENDOR_ACCOUNT_SEARCH_SESSION);

		//test param filter: omit title text in field
		$paramName = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'username', Sss_Ultility_CommonViewParamater::UNDERFINE);

		$filterParam['username'] = '';
		if ($paramName != Resources::_('VENDOR_NAME'))
			$filterParam['username'] = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'username', $paramName, Sss_Ultility_SessionName::VENDOR_ACCOUNT_SEARCH_SESSION);
		$filterParam['accounttype'] = Sss_Ultility_Setting::ACCOUNT_VENDOR;
		$limit = $this->getValueRequest(Sss_Ultility_CommonViewParamater::LIMIT, $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::LIMIT, Sss_Ultility_CommonViewParamater::UNDERFINE), Sss_Ultility_SessionName::VENDOR_ACCOUNT_SEARCH_SESSION);

		//get company list
		$list = $accountsTable->getListByType($limit, 0, $filterParam);
		$row = $list->list;
		$pagination = $list->pagination;
		$this->view->assign(Sss_Ultility_CommonViewParamater::FILTER_PARAM, $filterParam);
		$this->view->assign(Sss_Ultility_CommonViewParamater::LIMIT, $limit);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW, $row);
		$this->view->assign(Sss_Ultility_CommonViewParamater::PAGINATION, $pagination);
	}

	public function stockLocationsAction()
	{
		$stocklocationsTable = new Application_Model_Mapper_StockLocation();
		$get  = $this->getRequest()->getParams();
		$isSearch = isset($get['s']) && $get['s'] == 1;
		//get order, page, limit param
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD] = isset($get[Sss_Ultility_CommonViewParamater::ORDERFIELD]) ? $get[Sss_Ultility_CommonViewParamater::ORDERFIELD] : null;
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE]  = isset($get[Sss_Ultility_CommonViewParamater::ORDERTYPE]) ? $get[Sss_Ultility_CommonViewParamater::ORDERTYPE] : null;
		$filterParam[Sss_Ultility_CommonViewParamater::PAGE] = isset($get[Sss_Ultility_CommonViewParamater::PAGE]) ? $get[Sss_Ultility_CommonViewParamater::PAGE] : 1;
		//test param filter: omit title text in field
		$paramName    = $isSearch ? strcmp($this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'stocklocationname', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('STOCK_LOCATION_NAME')) == 0 ? '' : $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'stocklocationname', Sss_Ultility_CommonViewParamater::UNDERFINE) : '';
		$paramContact = $isSearch ? strcmp($this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'contact', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('STOCK_LOCATION_CONTACT')) == 0 ? '' : $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'contact', Sss_Ultility_CommonViewParamater::UNDERFINE) : '';
		$paramType    = $isSearch ? strcmp($this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'stocklocationtype', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('STOCK_LOCATION_TYPE')) == 0 ? '' : $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'stocklocationtype', Sss_Ultility_CommonViewParamater::UNDERFINE) : '';

		$filterParam['stocklocationname'] = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'stocklocationname', trim($paramName), Sss_Ultility_SessionName::STOCKLOCATIONS_SESSION);
		$filterParam['contact']            = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'contact', trim($paramContact), Sss_Ultility_SessionName::STOCKLOCATIONS_SESSION);
		$filterParam['stocklocationtype'] = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'stocklocationtype', trim($paramType), Sss_Ultility_SessionName::STOCKLOCATIONS_SESSION);
		$userInformation = Ovis_Controller::getLoggedUser();
		if ($userInformation && $userInformation['accounttype'] == Sss_Ultility_Setting::ACCOUNT_OVIS) {
			//visible stock location
			$stockLocationtId = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::VISIBLE_ID, -1);
			if (isset($stockLocationtId) && $stockLocationtId != -1) { 
				$stockLocation = $stocklocationsTable->findById((int) $stockLocationtId);
				$messageSuccessfull = $stockLocation->isarchived == 0 ? Resources::_('INVISIBLE_STOCK_LOCATION_SUCCESSFULL') : Resources::_('VISIBLE_STOCK_LOCATION_SUCCESSFULL');
				$messageFail = $stockLocation->isarchived == 0 ? Resources::_('INVISIBLE_STOCK_LOCATION_FAIL') : Resources::_('VISIBLE_STOCK_LOCATION_FAIL');
				$result = Sss_Ultility_InventoryFuction::invisibleOrVisibleStock($stockLocationtId);
				$message = $result == true ? $messageSuccessfull : $messageFail;
				$this->redirect($message, $this->view->url(array(
				Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
				Sss_Ultility_CommonViewParamater::ACTION => 'stock-locations'
				)));
			}
			//delete stock location
			$stockLocationtId = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::DELETE_ID, -1);
			if (isset($stockLocationtId) && $stockLocationtId != -1) {
				$result = Sss_Ultility_InventoryFuction::deleteStockLocation($stockLocationtId);
				$message = $result == true ? Resources::_('DELETE_STOCK_LOCATION_SUCCESSFULL') : Resources::_('DELETE_STOCK_LOCATION_FAIL');
				$this->redirect($message, $this->view->url(array(
				Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
				Sss_Ultility_CommonViewParamater::ACTION => 'stock-locations'
				)));
			}
		}
		//get Stock locations list
		$list       = $stocklocationsTable->getList($this->view->limit, 0, $filterParam, null, $userInformation['accounttype'] != Sss_Ultility_Setting::ACCOUNT_OVIS ? $userInformation['accountid'] : null);
		$row        = $list->list;
		$arrRelateStockLocation = Sss_Ultility_InventoryFuction::getRelateStockLocation($row);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ACCOUNT, $arrRelateStockLocation[Sss_Ultility_CommonViewParamater::ACCOUNT]);
		$this->view->assign(Sss_Ultility_CommonViewParamater::INVENTORY, $arrRelateStockLocation[Sss_Ultility_CommonViewParamater::INVENTORY]);
		$this->view->assign(Sss_Ultility_CommonViewParamater::DOCUMENT, $arrRelateStockLocation[Sss_Ultility_CommonViewParamater::DOCUMENT]);
		$this->view->assign(Sss_Ultility_CommonViewParamater::SHIPMENT, $arrRelateStockLocation[Sss_Ultility_CommonViewParamater::SHIPMENT]);
		$this->view->assign(Sss_Ultility_CommonViewParamater::INSTANCE, $arrRelateStockLocation[Sss_Ultility_CommonViewParamater::INSTANCE]);
		$this->view->assign(Sss_Ultility_CommonViewParamater::FILTER_PARAM, $filterParam);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW, $row);
		$this->view->assign(Sss_Ultility_CommonViewParamater::PAGINATION, $list->pagination);
		$orderQueryString = '';
		$orderString = '&' . Sss_Ultility_CommonViewParamater::PAGE . '=' . $filterParam[Sss_Ultility_CommonViewParamater::PAGE];
		$orderQueryString = $isSearch ? $orderString . '&s=1': $orderString;
		$queryString = '';
		if ($isSearch) {
			$queryString .= '&s=1';
		}
		if (!is_null($filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD])){
			$queryString .= '&' . Sss_Ultility_CommonViewParamater::ORDERFIELD . '=' . $filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD];
		}
		if (!is_null($filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE])){
			$queryString .= '&' . Sss_Ultility_CommonViewParamater::ORDERTYPE . '=' . $filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE];
		}
		$this->view->assign(Sss_Ultility_CommonViewParamater::QUERY_STRING, $queryString);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ORDER_QUERY_STRING, $orderQueryString);
		//action button
		if($userInformation['accounttype'] == Sss_Ultility_Setting::ACCOUNT_OVIS)
		{
			$actionbuttons = array(
			new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::ADD, 'add-stock-location', Resources::_('ADD_NEW_STOCK_LOCATION')),
			new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::EXPORT, 'stock-location-export?export=1', Resources::_('EXPORT')),
			new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::PRINTF, 'stock-location-export?print=1', Resources::_('PRINT')),
			new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::SEARCH, 'javascript:hideShow(this);', Resources::_('SEARCH'))
			);
		} else {
			$actionbuttons = array(
			new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::EXPORT, 'stock-location-export?export=1', Resources::_('EXPORT')),
			new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::PRINTF, 'stock-location-export?print=1', Resources::_('PRINT')),
			new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::SEARCH, 'javascript:hideShow(this);', Resources::_('SEARCH'))
			);
		}
		$this->view->assign(Sss_Ultility_CommonViewParamater::ACTION_BUTTONS, $actionbuttons);
		//get breadscrumb
		$breadscrumbs = array(
		new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
		new Sss_CommonEntity_BreadScrumb(Resources::_('STOCK_LOCATIONS'), '#')
		);
		$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
	}

	public function addStockLocationAction()
	{
		$userInformation = Ovis_Controller::getLoggedUser();
		if($userInformation['accounttype'] != Sss_Ultility_Setting::ACCOUNT_OVIS) {
			$this->_redirect('/user/login');
		}
		if($userInformation['accounttype'] == Sss_Ultility_Setting::ACCOUNT_OVIS) {
			$systemTypeTable = new Application_Model_Mapper_SystemType();
			$countryTable = new Application_Model_Mapper_Country();
			$stockLocationTable = new Application_Model_Mapper_StockLocation();
			$stockContructor = new Application_Model_StockLocation();
			$StockLocationCompanyOwnerTable = new Application_Model_Mapper_StockLocationCompanyOwner();
			//get stock location type
			$stockLocationTypeId = $this->getRequest()->getParam('systemtypeid', -1);
			$this->view->assign('stocklocationtype', $stockLocationTypeId);
			$stockLocationTypes = $systemTypeTable->getSystemBySystemName(Sss_Ultility_SystemName::STOCKLOCATION_TYPE);
			$this->view->assign(Sss_Ultility_CommonViewParamater::STOCKLOCATION_TYPES, $stockLocationTypes);
			//get country

			$this->view->assign('country_id', $stockLocationTypeId);
			$listCountry = $countryTable->getList();

			$this->view->assign(Sss_Ultility_CommonViewParamater::ROW, $listCountry);
			$params = $this->_request->getParams();
			//insert stock location
			if (isset($params[Sss_Ultility_CommonViewParamater::BTN_SAVE])) {
				if ($userInformation) {
					//upload stock location photo
					$fullPath = null;
					$fileName = $_FILES[Sss_Ultility_CommonViewParamater::FILE_UPLOAD][Sss_Ultility_CommonViewParamater::NAME];
					if ($fileName) {
						$filePath = $_FILES[Sss_Ultility_CommonViewParamater::FILE_UPLOAD][Sss_Ultility_CommonViewParamater::TMP_NAME];
						$newPath  = Sss_Ultility_CommonViewParamater::FILE_PATH_PHOTO_STOCK_LOCATION . $fileName;
						$uploadedFile = move_uploaded_file($filePath, $newPath);
						$fullPath     = '/' . Sss_Ultility_CommonViewParamater::FILE_PATH_PHOTO_STOCK_LOCATION . $fileName;
					}
					$stock = '';
					if (isset($params['stock'])) {
						$stock = $params['stock'];
					}
					$shepherd = '';
					if (isset($params['shepherd'])) {
						$shepherd = $params['shepherd'];
					}
					$createDate      = Sss_Ultility_Common::getDateTimeNumber();
					// Process adding new stock location
					$stockContructor->setStockLocationName(addslashes($params['stocklocationname']));
					$stockContructor->setPartner(addslashes($params['partner']));
					$setCountry = $params['country'] != '' ? $params['country'] : Sss_Ultility_Setting::DEFAILT_COUNTRY;
					$stockContructor->setCountry($setCountry);
					$stockContructor->setCity(addslashes($params['city']));
					$stockContructor->setContact(addslashes($params['contact']));
					$stockContructor->setContactPhone(addslashes($params['contact_phone']));
					$stockContructor->setStockLocationType($params['stocklocationtype']);
					$stockContructor->setStock($stock);
					$stockContructor->setShepherd($shepherd);
					$stockContructor->setPhoto($fullPath);
					$stockContructor->setAddress(addslashes($params['address']));
					$stockContructor->setCreatedDate($createDate);
					$stockContructor->setCreatedBy($userInformation['accountid']);
					$stockContructor->setUpdatedDate($createDate);
					$stockContructor->setUpdatedBy($userInformation['accountid']);
					$stockContructor->setIsarchived(0);
					$stockLocationId = $stockLocationTable->save($stockContructor);
					if (isset($stockLocationId)) {
						//add compnay owner to stock location
						$arrCompanyOwnerId = explode('_', $params['companyowner']);
						if (false != $arrCompanyOwnerId) {
							for ($i = 0; $i < count($arrCompanyOwnerId); $i++) {
								$companyOwnerId = $arrCompanyOwnerId[$i];
								if ($companyOwnerId > 0 && $companyOwnerId != '') {
									$stockCompanyOwnerContructor = new Application_Model_StockLocationCompanyOwner();
									$stockCompanyOwnerContructor->setCompanyOwner($companyOwnerId);
									$stockCompanyOwnerContructor->setStockLocation($stockLocationId);
									$StockLocationCompanyOwnerTable->save($stockCompanyOwnerContructor);
								}
							}
						}
						$this->view->assign(Sss_Ultility_CommonViewParamater::NOTICEMSG, Resources::_('ADD_STOCK_LOCATION_SUCCESSFULL'));
					} else {
						$this->view->assign(Sss_Ultility_CommonViewParamater::ERRORMSG, Resources::_('ADD_STOCK_LOCATION_FAIL'));
					}
					$this->_forward('stock-locations');
					return;
				}
			}
			//get breadscrumb
			$breadscrumbs = array(
				new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
				new Sss_CommonEntity_BreadScrumb(Resources::_('STOCK_LOCATIONS'), 'stock-locations'),
				new Sss_CommonEntity_BreadScrumb(Resources::_('ADD_NEW_STOCK_LOCATION'), '#')
			);
			$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
		}
	}

	public function editStockLocationAction()
	{
		$userInformation = Ovis_Controller::getLoggedUser();
		if($userInformation['accounttype'] != Sss_Ultility_Setting::ACCOUNT_OVIS) {
			$this->_redirect('/user/login');
		}
		if($userInformation['accounttype'] == Sss_Ultility_Setting::ACCOUNT_OVIS || $userInformation['accounttype'] == Sss_Ultility_Setting::ACCOUNT_CUSTOMER) {
			$systemTypeTable = new Application_Model_Mapper_SystemType();
			$countryTable = new Application_Model_Mapper_Country();
			$stockLocationTable = new Application_Model_Mapper_StockLocation();
			$inventoryTable = new Application_Model_Mapper_Inventory();

			$accountTable = new Application_Model_Mapper_Account();
			//get stock location type
			$stockLocationTypeId = $this->getRequest()->getParam('systemtypeid', -1);
			$this->view->assign('stocklocationtype', $stockLocationTypeId);
			$stockLocationTypes = $systemTypeTable->getSystemBySystemName(Sss_Ultility_SystemName::STOCKLOCATION_TYPE);
			$this->view->assign(Sss_Ultility_CommonViewParamater::STOCKLOCATION_TYPES, $stockLocationTypes);
			//get country
			$countryId = $this->getRequest()->getParam('country_id', -1);
			$this->view->assign('country_id', $countryId);
			$listCountry = $countryTable->getList();
			$this->view->assign(Sss_Ultility_CommonViewParamater::ROW, $listCountry);
			$params = $this->getRequest()->getPost();
			$stockLocationId = $this->getRequest()->getParam('stocklocationid', -1);
			if (($stockLocationId == -1 || (int) $stockLocationId == 0) && isset($params['stocklocationid'])) {
				$stockLocationId = $params['stocklocationid'];
			}
			$this->view->assign('stocklocationid', $stockLocationId);
			//get stock location by id
			$stockLocation = $stockLocationTable->findById($stockLocationId);
			$this->view->assign(Sss_Ultility_CommonViewParamater::STOCKLOCATION, $stockLocation);

			//get company owner account name by stock location
			$compnayOwner           = $accountTable->getCompanyOwnerByStockLocation($stockLocationId);
			$compnayOwnerName = '';
			$companyOwnerValue = '';
			foreach($compnayOwner as $c){
				if($compnayOwnerName != ''){
					$compnayOwnerName = $compnayOwnerName.', ';
					$companyOwnerValue = $companyOwnerValue.'_';
				}
				$companyOwnerValue = $companyOwnerValue.$c['accountid'];
				$compnayOwnerName = $compnayOwnerName.$c['fullname'];
			}
			$this->view->assign('companyOwnerValue', $companyOwnerValue);
			$this->view->assign(Sss_Ultility_CommonViewParamater::ACCOUNT, $compnayOwnerName);
			//get inventory by stock location
			$inventory           = $inventoryTable->getInventoryByStockLocation($stockLocationId);
			$this->view->assign(Sss_Ultility_CommonViewParamater::INVENTORY, $inventory);
			$strController = Sss_Ultility_CommonViewParamater::INVENTORY;
			$strAction     = 'stock-locations';
			if (isset($params[Sss_Ultility_CommonViewParamater::BTN_SAVE]) && $stockLocationId != -1) {
				if ($userInformation) {
					$stock = 0;
					if (isset($params['stock'])) {
						$stock = $params['stock'];
					}
					$shepherd = 0;
					if (isset($params['shepherd'])) {
						$shepherd = $params['shepherd'];
					}
					$data               = array(
						'stocklocationname' => addslashes($params['stocklocationname']),
						'partner' => addslashes($params['partner']),
						'country' => $params['country'],
						'city' => addslashes($params['city']),
						'contact' => addslashes($params['contact']),
						'contact_phone' => addslashes($params['contact_phone']),
						'stocklocationtype' => $params['stocklocationtype'],
						'stock' => $stock,
						'shepherd' => $shepherd,
						'address' => addslashes($params['address'])
					);
					$result = Sss_Ultility_InventoryFuction::editStockLocation($stockLocationId,$stockLocation,$data,$params['companyowner']);
					if($result == true) {
						$this->redirect(Resources::_('EDIT_STOCK_LOCATION_SUCCESSFULL'), $this->view->url(array(
						Sss_Ultility_CommonViewParamater::CONTROLLER => $strController,
						Sss_Ultility_CommonViewParamater::ACTION => $strAction
						)) . $queryString);
					} else {
						$this->redirect(Resources::_('EDIT_STOCK_LOCATION_FAIL'), $this->view->url(array(
						Sss_Ultility_CommonViewParamater::CONTROLLER => $strController,
						Sss_Ultility_CommonViewParamater::ACTION => $strAction
						)) . $queryString);
					}
				}
			}
			//get breadscrumb
			$breadscrumbs = array(
				new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
				new Sss_CommonEntity_BreadScrumb(Resources::_('STOCK_LOCATIONS'), 'stock-locations'),
				new Sss_CommonEntity_BreadScrumb(Resources::_('EDIT_STOCK_LOCATION'), '#')
			);
			$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
		}
	}

	public function stockLocationExportAction()
	{
		$stocklocationsTable = New Application_Model_Mapper_StockLocation();
		$inventoryTable = new Application_Model_Mapper_Inventory();

		//get order, page, limit param
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD] = isset($get[Sss_Ultility_CommonViewParamater::ORDERFIELD]) ? $get[Sss_Ultility_CommonViewParamater::ORDERFIELD] : null;
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE]  = isset($get[Sss_Ultility_CommonViewParamater::ORDERTYPE]) ? $get[Sss_Ultility_CommonViewParamater::ORDERTYPE] : null;
		$filterParam[Sss_Ultility_CommonViewParamater::PAGE] = isset($get[Sss_Ultility_CommonViewParamater::PAGE]) ? $get[Sss_Ultility_CommonViewParamater::PAGE] : 1;

		//test param filter: omit title text in field
		$paramName     = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'stocklocationname', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$paramContact  = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'contact', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$paramType     = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'stocklocationtype', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$paramStock    = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'stock', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$paramShepherd = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'shepherd', Sss_Ultility_CommonViewParamater::UNDERFINE);



		$filterParam['stocklocationname'] = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'stocklocationname', $paramName, Sss_Ultility_SessionName::STOCKLOCATIONS_SESSION);
		$filterParam['contact']            = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'contact', $paramContact, Sss_Ultility_SessionName::STOCKLOCATIONS_SESSION);
		$filterParam['stocklocationtype'] = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'stocklocationtype', $paramType, Sss_Ultility_SessionName::STOCKLOCATIONS_SESSION);
		$filterParam['stock']              = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'stock', $paramStock, Sss_Ultility_SessionName::STOCKLOCATIONS_SESSION);
		$filterParam['shepherd']           = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'shepherd', $paramShepherd, Sss_Ultility_SessionName::STOCKLOCATIONS_SESSION);



		//get Stock locations list
		$list = $stocklocationsTable->getList(-1, 0, $filterParam);
		$rowAll  = $list->list;
		$listInventory    = array();
		foreach ((array) $rowAll as $r) {
			//get inventory by stock location
			$inventory           = $inventoryTable->getInventoryByStockLocation($r['stocklocationid']);
			if($inventory != false){
				$listInventory[] = count($inventory);
			}
			else{
				$listInventory[] = 0;
			}
		}
		$pagination = $list->pagination;
		$this->view->assign(Sss_Ultility_CommonViewParamater::INVENTORY, $listInventory);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW, $rowAll);
		$this->view->assign(Sss_Ultility_CommonViewParamater::PAGINATION, $pagination);
		$count = ((($pagination->pagecurrent * Sss_Ultility_Setting::PAGE_SIZE) - Sss_Ultility_Setting::PAGE_SIZE));
		$columnNames = array(
				Resources::_('ID'),
				Resources::_('NAME'),
				Resources::_('COMPANY_OWNER'),
				Resources::_('PARTNER'),
				Resources::_('COUNTRY'),
				Resources::_('CONTACT_PERSION'),
				Resources::_('CITY'),
				Resources::_('TYPE'),
				Resources::_('STOCK'),
				Resources::_('SHEPHERD')
		);

		$arrData = array();
		$index = 0;
		foreach((array)$rowAll as $row)
		{
			$count++;
			$arrData[$index][] = $count;
			$arrData[$index][] = $row['stocklocationname'];
			$arrData[$index][] = $row[$row['fullname']];
			$arrData[$index][] = $row['partner'];
			$arrData[$index][] = $row['country'];
			$arrData[$index][] = $row['contact'];
			$arrData[$index][] = $row['city'];
			$arrData[$index][] = $row['stocklocationtype'];
			$inventory           = $inventoryTable->getInventoryByStockLocation($row['stocklocationid']);
			if($inventory != false){
				$arrData[$index][] = Resources::_('YES');
			}
			else{
				$arrData[$index][] = Resources::_('NO');
			}
			$arrData[$index][] = $row['shepherd'] ? Resources::_('YES'):Resources::_('NO');
			$index++;
		}
		if(isset($_GET['export']))
			$this->exportDataToExcel($columnNames, $arrData, Resources::_('STOCK_LOCATIONS'));
	}

	public function stockLocationCompanyOwnerSearchAction()
	{
		$accountsTable = new Application_Model_Mapper_Account();
		//get order, page, limit param
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD] = $this->getValueRequest(Sss_Ultility_CommonViewParamater::ORDERFIELD, $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::ORDERFIELD, Sss_Ultility_CommonViewParamater::UNDERFINE), Sss_Ultility_SessionName::STOCKLOCATION_COMPANY_OWNER_SEARCH_SESSION);
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE] = $this->getValueRequest(Sss_Ultility_CommonViewParamater::ORDERTYPE, $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::ORDERTYPE, Sss_Ultility_CommonViewParamater::UNDERFINE), Sss_Ultility_SessionName::STOCKLOCATION_COMPANY_OWNER_SEARCH_SESSION);
		$filterParam[Sss_Ultility_CommonViewParamater::PAGE] = $this->getValueRequest(Sss_Ultility_CommonViewParamater::PAGE, $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::PAGE, Sss_Ultility_CommonViewParamater::UNDERFINE), Sss_Ultility_SessionName::STOCKLOCATION_COMPANY_OWNER_SEARCH_SESSION);
		$limit = $this->getValueRequest(Sss_Ultility_CommonViewParamater::LIMIT, $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::LIMIT, Sss_Ultility_CommonViewParamater::UNDERFINE), Sss_Ultility_SessionName::STOCKLOCATION_COMPANY_OWNER_SEARCH_SESSION);

		//test param filter: omit title text in field
		$paramName = $this->getRequest()->getParam('fullname', Sss_Ultility_CommonViewParamater::UNDERFINE);
		if($paramName == Sss_Ultility_CommonViewParamater::UNDERFINE) {
			$paramName = Resources::_('STOCK_LOCATION_NAME');
		}

		$filterParam['username'] = '';
		if ($paramName != Resources::_('STOCK_LOCATION_NAME'))
			$filterParam['fullname'] = $this->getValueRequest('fullname', $paramName, Sss_Ultility_SessionName::STOCKLOCATION_COMPANY_OWNER_SEARCH_SESSION);
		$filterParam['accounttype'] = Sss_Ultility_Setting::ACCOUNT_CUSTOMER;
		$limit = $this->getValueRequest(Sss_Ultility_CommonViewParamater::LIMIT, $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::LIMIT, Sss_Ultility_CommonViewParamater::UNDERFINE), Sss_Ultility_SessionName::STOCKLOCATION_COMPANY_OWNER_SEARCH_SESSION);
		$stockLocation = $this->getRequest()->getParam('stocklocationid', -1);
		$this->view->assign('stocklocationid', $stockLocation);
		$filterParam['isactivated'] = 1;

		//get company list
		$list = $accountsTable->getListByType($limit, 0, $filterParam);
		if ($stockLocation != -1) {
			$filterParam['stocklocation'] = $stockLocation;
			$list = $accountsTable->getListSearchByType($limit, 0, $filterParam);
		}
		$row = $list->list;
		$pagination = $list->pagination;
		$this->view->assign(Sss_Ultility_CommonViewParamater::FILTER_PARAM, $filterParam);
		$this->view->assign(Sss_Ultility_CommonViewParamater::LIMIT, $limit);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW, $row);
		$this->view->assign(Sss_Ultility_CommonViewParamater::PAGINATION, $pagination);
	}

	public function hardwareAction()
	{
		$vendorTable = new Application_Model_Mapper_Vendor();
		$hardwareTable = new Application_Model_Mapper_Hardware();
		$get = $this->getRequest()->getParams();
		$isSearch = isset($get['s']) && $get['s'] == 1;
		//get order, page, limit param
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD] = isset($get[Sss_Ultility_CommonViewParamater::ORDERFIELD]) ? $get[Sss_Ultility_CommonViewParamater::ORDERFIELD] : null;
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE] = isset($get[Sss_Ultility_CommonViewParamater::ORDERTYPE]) ? $get[Sss_Ultility_CommonViewParamater::ORDERTYPE] : null;
		$filterParam[Sss_Ultility_CommonViewParamater::PAGE] = isset($get[Sss_Ultility_CommonViewParamater::PAGE]) ? $get[Sss_Ultility_CommonViewParamater::PAGE] : 1;
		//test param filter: omit title text in field
		$paramName = $isSearch ? strcmp($this->getRequest()->getParam('name', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('NAME')) == 0 ? '' : $this->getRequest()->getParam('name', Sss_Ultility_CommonViewParamater::UNDERFINE)  : '';
		$paramType = $isSearch ? strcmp($this->getRequest()->getParam('typename', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('TYPE')) == 0 ? '' : $this->getRequest()->getParam('typename', Sss_Ultility_CommonViewParamater::UNDERFINE)  : '';
		$paramVendor = $isSearch ? strcmp($this->getRequest()->getParam('vendor', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('ALL')) == 0 ? '' : $this->getRequest()->getParam('vendor', Sss_Ultility_CommonViewParamater::UNDERFINE)  : '';
		$paramSerial = $isSearch ? strcmp($this->getRequest()->getParam('serial_number', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('SERIAL')) == 0 ? '' : $this->getRequest()->getParam('serial_number', Sss_Ultility_CommonViewParamater::UNDERFINE)  : '';
		$paramLocation = $isSearch ? strcmp($this->getRequest()->getParam('stocklocationname', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('LOCATION')) == 0 ? '' : $this->getRequest()->getParam('stocklocationname', Sss_Ultility_CommonViewParamater::UNDERFINE)  : '';
		$paramStatus = $isSearch ? strcmp($this->getRequest()->getParam('status_name', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('STATUS')) == 0 ? '' : $this->getRequest()->getParam('status_name', Sss_Ultility_CommonViewParamater::UNDERFINE)  : '';
		$paramAllocation = $isSearch ? strcmp($this->getRequest()->getParam('allocation', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('ALLOCATION')) == 0 ? '' : $this->getRequest()->getParam('allocation', Sss_Ultility_CommonViewParamater::UNDERFINE)  : '';
		//get harware filter
		$filterParam['hardwarename'] = $this->getValueRequest('name', trim($paramName), Sss_Ultility_SessionName::HARDWARE_SESSION);
		$filterParam['typename'] = $this->getValueRequest('typename', trim($paramType), Sss_Ultility_SessionName::HARDWARE_SESSION);
		$filterParam['vendor'] = $this->getValueRequest('vendor', trim($paramVendor), Sss_Ultility_SessionName::HARDWARE_SESSION);
		$filterParam['serial_number'] = $this->getValueRequest('serial_number', trim($paramSerial), Sss_Ultility_SessionName::HARDWARE_SESSION);
		$filterParam['stocklocationname'] = $this->getValueRequest('stocklocationname', trim($paramLocation), Sss_Ultility_SessionName::HARDWARE_SESSION);
		$filterParam['status_name'] = $this->getValueRequest('status_name', $paramStatus, Sss_Ultility_SessionName::HARDWARE_SESSION);
		$filterParam['allocation'] = $this->getValueRequest('allocation', trim($paramAllocation), Sss_Ultility_SessionName::HARDWARE_SESSION);
		$userInformation = Ovis_Controller::getLoggedUser();
		$vendor = $vendorTable->getList(); //get vendor
		$this->view->assign(Sss_Ultility_CommonViewParamater::VENDOR, $vendor);
		//insert hardware
		$params = $this->_request->getPost();
		if (isset($params[Sss_Ultility_CommonViewParamater::BTN_SAVE])) {
			// Get hardwareIds
			$hardwareIds = Sss_Ultility_InventoryFuction::gethardwareIds($userInformation);
			if ($hardwareIds != null) {
				$this->redirect('', $this->view->url(array(
							Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
							Sss_Ultility_CommonViewParamater::ACTION => 'edit-hardware'
						)) . '?hardwareid=&'. Sss_Ultility_CommonViewParamater::HARDWARE_IDS . '=' . $hardwareIds);
			} else {
				$this->redirect(Resources::_('NOT_HARDWARE_IMPORT'), $this->view->url(array(
							Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
							Sss_Ultility_CommonViewParamater::ACTION => $this->view->actionName
						)));
			}
		}
		if (isset($params[Sss_Ultility_CommonViewParamater::EDIT_HARDWARE_IDS]) && $params[Sss_Ultility_CommonViewParamater::EDIT_HARDWARE_IDS] != '') {
			$edit = $params['owner'] . ',' . $params['hardwaretype'] . ',' . $params['vendor'] . ',' . $params['stocklocationid'] . ',' . $params['status'] . ',' . $params['buyer'] . ',' . $params['soft_version'] . ',' . $params['hard_version'];
			$this->redirect('', $this->view->url(array(
						Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
						Sss_Ultility_CommonViewParamater::ACTION => 'edit-hardware'
					)) . '?hardwareid=&' . Sss_Ultility_CommonViewParamater::HARDWARE_IDS . '=' . $params[Sss_Ultility_CommonViewParamater::EDIT_HARDWARE_IDS] . '&edit=' . $edit . '&' . Sss_Ultility_CommonViewParamater::TOTAL_ITEM . '=' . $params[Sss_Ultility_CommonViewParamater::TOTAL_ITEM]);
		}
		if (isset($params[Sss_Ultility_CommonViewParamater::HARDWARE_IDS]) && $params[Sss_Ultility_CommonViewParamater::HARDWARE_IDS] != '') {
			$arrHardwareId = explode(',',$params[Sss_Ultility_CommonViewParamater::HARDWARE_IDS]); //assign hardware to item
			if (false != $arrHardwareId) {
				$messages = Sss_Ultility_InventoryFuction::assignHardware($arrHardwareId);
				$this->view->assign(Sss_Ultility_CommonViewParamater::NOTICEMSG, $messages);
			}
		}
		if ($userInformation && $userInformation['accounttype'] == Sss_Ultility_Setting::ACCOUNT_OVIS) {
			$deleteHardwareId = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::DELETE_ID, -1); //delete hardware
			if(isset($deleteHardwareId) && ($deleteHardwareId != -1)) {
				$messages = Sss_Ultility_InventoryFuction::deleteHardware($deleteHardwareId);
				$this->view->assign(Sss_Ultility_CommonViewParamater::NOTICEMSG, $messages);
			}
		}
		//get hardware list
		$list = $hardwareTable->getListHardware($this->view->limit, 0, $filterParam, $userInformation['accounttype'] != Sss_Ultility_Setting::ACCOUNT_OVIS ? $userInformation['accountid'] : null);
		$this->view->assign('accounttype', $userInformation['accounttype'] == Sss_Ultility_Setting::ACCOUNT_OVIS ? 1 : 0);
		$row = $list->list;
		$pagination = $list->pagination;
		$this->view->assign(Sss_Ultility_CommonViewParamater::FILTER_PARAM, $filterParam);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW, $row);
		$this->view->assign(Sss_Ultility_CommonViewParamater::PAGINATION, $pagination);
		$stringUrl = '&' . Sss_Ultility_CommonViewParamater::PAGE . '=' . $filterParam[Sss_Ultility_CommonViewParamater::PAGE];
		$orderQueryString = $isSearch ? $stringUrl . '&s=1' : $stringUrl;
		$queryString = '';
		if ($isSearch)
			$queryString .= '&s=1';
		if (!is_null($filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD])) {
			$queryString .= '&' . Sss_Ultility_CommonViewParamater::ORDERFIELD . '=' . $filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD];
		}
		if (!is_null($filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE])) {
			$queryString .= '&' . Sss_Ultility_CommonViewParamater::ORDERTYPE . '=' . $filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE];
		}
		$this->view->assign(Sss_Ultility_CommonViewParamater::QUERY_STRING, $queryString);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ORDER_QUERY_STRING, $orderQueryString);
		// action buttons
		$actionbuttons = Sss_Ultility_InventoryFuction::arractionButton($userInformation);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ACTION_BUTTONS, $actionbuttons);
		//get breadscrumb
		$breadscrumbs = array(
			new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
			new Sss_CommonEntity_BreadScrumb(Resources::_('HARDWARE'), '#')
		);
		$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
	}

	public function addHardwareAction()
	{
		$userInformation = Ovis_Controller::getLoggedUser();
		if ($userInformation['accounttype'] != Sss_Ultility_Setting::ACCOUNT_OVIS) {
			$this->_redirect('/user/login');
		}
		$hardwareTable = new Application_Model_Mapper_Hardware();
		$hardwareContructor = new Application_Model_Hardware();
		$systemTypeTable = New Application_Model_Mapper_SystemType();
		$vendorTable = new Application_Model_Mapper_Vendor();
		$stockLocationTable = new Application_Model_Mapper_StockLocation();
		$hardwareTypes = $systemTypeTable->getSystemBySystemName(Sss_Ultility_SystemName::HARDWARETYPE);//get hardware type
		$this->view->assign(Sss_Ultility_CommonViewParamater::HARDWATE_TYPES, $hardwareTypes);
		$hardwareStatus = $systemTypeTable->getSystemBySystemName(Sss_Ultility_SystemName::STATUS);//get hardware status
		$this->view->assign(Sss_Ultility_CommonViewParamater::HARDWATE_STATUS, $hardwareStatus);
		$vendor = $vendorTable->getList();//get vendor
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW, $vendor);
		$rmaType = $systemTypeTable->getSystemBySystemName(Sss_Ultility_SystemName::RMATYPE);//get type rma
		$this->view->assign(Sss_Ultility_CommonViewParamater::RMA_TYPE, $rmaType);
		//insert hardware
		$params = $this->_request->getParams();
		$stockLocationId = $this->getRequest()->getParam('stocklocationid', -1);
		if (($stockLocationId == -1 || (int) $stockLocationId == 0) && isset($params['stocklocationid']))
			$stockLocationId = $params['stocklocationid'];
		$this->view->assign('stocklocationid', $stockLocationId);
		$stockLocations = $stockLocationTable->getAllStockLocation($stockLocationId);//get stock location
		$this->view->assign(Sss_Ultility_CommonViewParamater::STOCKLOCATION, $stockLocations);
		$stockLocation = $stockLocationTable->findById($stockLocationId);//get stock location by id
		$allocation = Resources::_('NOT_ALLOCATED');//get allocation name
		if ($userInformation && isset($params[Sss_Ultility_CommonViewParamater::BTN_SAVE])) {
				//upload document
				$fullPath = null;
				$fileName = $_FILES[Sss_Ultility_CommonViewParamater::FILE_UPLOAD][Sss_Ultility_CommonViewParamater::NAME];
				if ($fileName) {
					$filePath = $_FILES[Sss_Ultility_CommonViewParamater::FILE_UPLOAD][Sss_Ultility_CommonViewParamater::TMP_NAME];
					$newPath = Sss_Ultility_CommonViewParamater::FILE_PATH_HARDWARE . $fileName;
					move_uploaded_file($filePath, $newPath);
					$fullPath = '/' . Sss_Ultility_CommonViewParamater::FILE_PATH_HARDWARE . $fileName;
				}
				$createBy = $userInformation['accountid'];
				$allocation = $params['allocation'];
				$allocation = ($stockLocationId != -1 && $stockLocationId != '') ? $stockLocation->stocklocationname : $params['allocation'];
				//check status valid of hardware
				$valid = (isset($params['valid']) && $params['valid'] == 'on') ? Sss_Ultility_Setting::HARDWARE_VALID : Sss_Ultility_Setting::HARDWARE_INVALID; 
				//process add hardware
				$hardwareContructor->setHardwareName(addslashes($params['hardwarename']));
				$hardwareContructor->setSerialNumber(addslashes($params['serial_number']));
				$hardwareContructor->setVendor($params['vendor']);
				$hardwareContructor->setBuyer(addslashes($params['buyer']));
				$hardwareContructor->setHardwaretype($params['hardwaretype']);
				$hardwareContructor->setStatus($params['status']);
				$hardwareContructor->setAllocation(addslashes($allocation));
				$hardwareContructor->setPhoto($fullPath);
				$hardwareContructor->setSoftVersion(addslashes($params['soft_version']));
				$hardwareContructor->setHardVersion(addslashes($params['hard_version']));
				$hardwareContructor->setCreatedBy($createBy);
				$hardwareContructor->setUpdatedBy($createBy);
				$hardwareContructor->setCreatedDate(Sss_Ultility_Common::getDateTimeNumber());
				$hardwareContructor->setUpdatedDate(Sss_Ultility_Common::getDateTimeNumber());
				$hardwareContructor->setOwner(addslashes($params['owner']));
				$hardwareContructor->setNote(addslashes($params['note']));
				$hardwareContructor->setRmaType($params['rma_type']);
				$hardwareContructor->setValid($valid);
				$hardwareContructor->setRmaStatus(Sss_Ultility_Setting::RMA_STATUS_OPEN);
				$hardwareId = $hardwareTable->save($hardwareContructor);
				if (isset($hardwareId)) {
					Sss_Ultility_InventoryFuction::addInventory($stockLocationId,$params,$createBy,$hardwareId);//add inventory when add hardware successfull
					//add ticket by hardware
					$arrLinkId = explode('_', $params['linkid']);
					Sss_Ultility_InventoryFuction::addTicketByHardware($arrLinkId,$hardwareId);
					//add document by hardware
					$arrDocumentId = explode('_',$params['documentid']);
					Sss_Ultility_InventoryFuction::addDocumentByHardware($arrDocumentId,$hardwareId);
					$params = null;
					$this->redirect(Resources::_('ADD_HARDWARE_SUCCESSFULL'), $this->view->url(array(
								Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
								Sss_Ultility_CommonViewParamater::ACTION => 'hardware'
							)) . $queryString);
				} else {
					$params = null;
					$this->redirect(Resources::_('ADD_HARDWARE_FAILED'), $this->view->url(array(
								Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
								Sss_Ultility_CommonViewParamater::ACTION => 'hardware'
							)) . $queryString);
				}
		}
		$breadscrumbs = array(
			new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
			new Sss_CommonEntity_BreadScrumb(Resources::_('HARDWARE'), '#'),
			new Sss_CommonEntity_BreadScrumb(Resources::_('ADD_NEW_HARDWARE'), '#')
		);
		$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
	}

	public function editHardwareAction()
	{
		$userInformation = Ovis_Controller::getLoggedUser();
		if ($userInformation['accounttype'] != Sss_Ultility_Setting::ACCOUNT_OVIS) {
			$this->_redirect('/user/login');
		}
		$hardwareTable = new Application_Model_Mapper_Hardware();
		$systemTypeTable = new Application_Model_Mapper_SystemType();
		$vendorTable = new Application_Model_Mapper_Vendor();
		$documentTable = new Application_Model_Mapper_Document();
		$linkTable = new Application_Model_Mapper_Link();
		$stockLocationTable = new Application_Model_Mapper_StockLocation();

		//get hardware type
		$hardwareTypes = $systemTypeTable->getSystemBySystemName(Sss_Ultility_SystemName::HARDWARETYPE);
		$this->view->assign(Sss_Ultility_CommonViewParamater::HARDWATE_TYPES, $hardwareTypes);

		//get hardware status
		$hardwareStatus = $systemTypeTable->getSystemBySystemName(Sss_Ultility_SystemName::STATUS);
		$this->view->assign(Sss_Ultility_CommonViewParamater::HARDWATE_STATUS, $hardwareStatus);

		//get vendor
		$vendor = $vendorTable->getList();
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW, $vendor);
		$params = $this->getRequest()->getPost();
		$hardwareId = $this->getRequest()->getParam('hardwareid', -1);
		if (($hardwareId == -1 || (int) $hardwareId == 0) && isset($params['hardwareid']))
			$hardwareId = $params['hardwareid'];
		$this->view->assign('hardwareid', $hardwareId);
		$hardwareIds = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::HARDWARE_IDS, -1);
		if (($hardwareIds == -1 || (int) $hardwareIds == 0) && isset($params[Sss_Ultility_CommonViewParamater::HARDWARE_IDS])) {
			$hardwareIds = $params[Sss_Ultility_CommonViewParamater::HARDWARE_IDS];
		}
		$this->view->assign(Sss_Ultility_CommonViewParamater::HARDWARE_IDS, $hardwareIds);

		$arrHardwareIds = $hardwareIds != -1 ? explode(',', $hardwareIds) : '';
		$hardwareIdDefault = $hardwareIds != -1 ? $arrHardwareIds[0] : '';
		//count total hardware invalid when click checkbox
		$arrData = Sss_Ultility_InventoryFuction::countTotalValid($hardwareTable,$hardwareIds);
		$this->view->assign(Sss_Ultility_CommonViewParamater::TOTAL_INVALID, $arrData['totalValid']);

		//total hardware click
		$totalItem = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::TOTAL_ITEM, -1);
		$this->view->assign(Sss_Ultility_CommonViewParamater::TOTAL_ITEM, $totalItem);

		$edit = $this->getRequest()->getParam('edit', -1);
		$arrManyHardware = Sss_Ultility_InventoryFuction::setValueManyHardware($edit);
		$this->view->assign('howner', $arrManyHardware['howner']);
		$this->view->assign('hvendor', $arrManyHardware['hvendor']);
		$this->view->assign('huser', $arrManyHardware['huser']);
		$this->view->assign('htype', $arrManyHardware['htype']);
		$this->view->assign('hlocation', $arrManyHardware['hlocation']);
		$this->view->assign('hstatus', $arrManyHardware['hstatus']);
		$this->view->assign('hsoft', $arrManyHardware['hsoft']);
		$this->view->assign('hhanrd', $arrManyHardware['hhanrd']);
		//get hardware by id
		$value = $hardwareId != -1 ? $hardwareId : $arrData['hardwareIdDefault'];
		$hardware = $hardwareTable->getHardwareById($value, 1);
		$stockLocationId = $this->getRequest()->getParam('stocklocationid', -1);
		if (($stockLocationId == -1 || (int) $stockLocationId == 0) && isset($params['stocklocationid'])) {
			$stockLocationId = $params['stocklocationid'];
		}
		$this->view->assign('stocklocationid', $stockLocationId);
		//get stock location
		$stockLocations = $stockLocationTable->getAllStockLocation();
		$this->view->assign(Sss_Ultility_CommonViewParamater::STOCKLOCATION, $stockLocations);

		//get stock location by id
		$arrValue = Sss_Ultility_InventoryFuction::getStockLocationId($hardwareTable,$stockLocationTable,$stockLocationId,$hardware,$hardwareId,$hardwareIdDefault);
		$stockLocation = $arrValue['stocklocation'];
		$this->view->assign(Sss_Ultility_CommonViewParamater::HARDWARE, $arrValue['hardware']);
		$this->view->assign('hardwareDefault', $arrValue['hardwareDefault']);

		//get document list
		$documents = $documentTable->getList($hardwareId);
		$documents = $hardwareId == '' ? null : $documents;
		$this->view->assign(Sss_Ultility_CommonViewParamater::DOCUMENT, $documents);

		//get ticket list
		$tickets = $linkTable->getList($hardwareId);
		$tickets = $hardwareId == '' ? null : $tickets;
		$this->view->assign(Sss_Ultility_CommonViewParamater::LINK, $tickets);
		$queryString = $hardwareIds != -1 ? '?hardwareid=&' . Sss_Ultility_CommonViewParamater::HARDWARE_IDS . '=' . $hardwareIds : '';
		$this->view->assign(Sss_Ultility_CommonViewParamater::QUERY_STRING, $queryString);

		//insert hardware
		if ($params && isset($params[Sss_Ultility_CommonViewParamater::BTN_SAVE]) && $userInformation) { 
			$message = Sss_Ultility_InventoryFuction::saveEditHardware($hardwareId,$hardwareIds,$arrHardwareIds,$userInformation,$params,$stockLocation);
			$this->redirect($message, $this->view->url(array(
					Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
					Sss_Ultility_CommonViewParamater::ACTION => 'hardware'
			)));
		}
		//get breadscrumb
		$breadscrumbs = Sss_Ultility_InventoryFuction::breadscrumbEditHardware($this->_menuName);
		$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
	}

	public function hardwareExportAction()
	{
		$hardwareTable = new Application_Model_Mapper_Hardware();
		//get order, page, limit param
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD] = isset($get[Sss_Ultility_CommonViewParamater::ORDERFIELD]) ? $get[Sss_Ultility_CommonViewParamater::ORDERFIELD] : null;
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE] = isset($get[Sss_Ultility_CommonViewParamater::ORDERTYPE]) ? $get[Sss_Ultility_CommonViewParamater::ORDERTYPE] : null;
		$filterParam[Sss_Ultility_CommonViewParamater::PAGE] = isset($get[Sss_Ultility_CommonViewParamater::PAGE]) ? $get[Sss_Ultility_CommonViewParamater::PAGE] : 1;
		//test param filter: omit title text in field
		$paramName = strcmp($this->getRequest()->getParam('hardwarename', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('NAME')) == 0 ? '' : $this->getRequest()->getParam('hardwarename', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$paramType = strcmp($this->getRequest()->getParam('typename', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('TYPE')) == 0 ? '' : $this->getRequest()->getParam('typename', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$paramVendor = strcmp($this->getRequest()->getParam('vendorname', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('VENDOR')) == 0 ? '' : $this->getRequest()->getParam('vendorname', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$paramSerial = strcmp($this->getRequest()->getParam('serial_number', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('SERIAL')) == 0 ? '' : $this->getRequest()->getParam('serial_number', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$paramLocation = strcmp($this->getRequest()->getParam('stocklocationname', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('LOCATION')) == 0 ? '' : $this->getRequest()->getParam('stocklocationname', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$paramStatus = strcmp($this->getRequest()->getParam('status', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('STATUS')) == 0 ? '' : $this->getRequest()->getParam('status', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$paramAllocation = strcmp($this->getRequest()->getParam('allocation', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('ALLOCATION')) == 0 ? '' : $this->getRequest()->getParam('allocation', Sss_Ultility_CommonViewParamater::UNDERFINE);
		//get parameter of shepherd intances
		$intanceId = $this->getRequest()->getParam('intanceId');
		if (!empty($intanceId)) {
			$isSearch = $this->getRequest()->getParam('isSearch');
			if (!empty($isSearch)) {
				$paramName = strcmp($this->getRequest()->getParam('hardwarename', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('NAME')) == 0 ? '' : $this->getRequest()->getParam('hardwarename', Sss_Ultility_CommonViewParamater::UNDERFINE);
				$paramType = strcmp($this->getRequest()->getParam('typename', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('TYPE')) == 0 ? '' : $this->getRequest()->getParam('typename', Sss_Ultility_CommonViewParamater::UNDERFINE);
				$paramVendor = strcmp($this->getRequest()->getParam('vendorname', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('VENDOR')) == 0 ? '' : $this->getRequest()->getParam('vendorname', Sss_Ultility_CommonViewParamater::UNDERFINE);
				$paramSerial = strcmp($this->getRequest()->getParam('serial_number', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('SERIAL')) == 0 ? '' : $this->getRequest()->getParam('serial_number', Sss_Ultility_CommonViewParamater::UNDERFINE);
				$paramLocation = strcmp($this->getRequest()->getParam('stocklocationname', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('LOCATION')) == 0 ? '' : $this->getRequest()->getParam('stocklocationname', Sss_Ultility_CommonViewParamater::UNDERFINE);
				$paramStatus = strcmp($this->getRequest()->getParam('status', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('STATUS')) == 0 ? '' : $this->getRequest()->getParam('status', Sss_Ultility_CommonViewParamater::UNDERFINE);
				$paramAllocation = strcmp($this->getRequest()->getParam('allocation', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('ALLOCATION')) == 0 ? '' : $this->getRequest()->getParam('allocation', Sss_Ultility_CommonViewParamater::UNDERFINE);
				$filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD] = isset($get[Sss_Ultility_CommonViewParamater::ORDERFIELD]) ? $get[Sss_Ultility_CommonViewParamater::ORDERFIELD] : null;
				$filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE] = isset($get[Sss_Ultility_CommonViewParamater::ORDERTYPE]) ? $get[Sss_Ultility_CommonViewParamater::ORDERTYPE] : null;
				$filterParam[Sss_Ultility_CommonViewParamater::PAGE] = isset($get[Sss_Ultility_CommonViewParamater::PAGE]) ? $get[Sss_Ultility_CommonViewParamater::PAGE] : 1;
			}
		}
		//get harware filter
		$filterParam['hardwarename'] = $this->getValueRequest('hardwarename', $paramName, Sss_Ultility_SessionName::HARDWARE_SESSION);
		$filterParam['typename'] = $this->getValueRequest('typename', $paramType, Sss_Ultility_SessionName::HARDWARE_SESSION);
		$filterParam['vendorname'] = $this->getValueRequest('vendorname', $paramVendor, Sss_Ultility_SessionName::HARDWARE_SESSION);
		$filterParam['serial_number'] = $this->getValueRequest('serial_number', $paramSerial, Sss_Ultility_SessionName::HARDWARE_SESSION);
		$filterParam['stocklocationname'] = $this->getValueRequest('stocklocationname', $paramLocation, Sss_Ultility_SessionName::HARDWARE_SESSION);
		$filterParam['status'] = $this->getValueRequest('status', $paramStatus, Sss_Ultility_SessionName::HARDWARE_SESSION);
		$filterParam['allocation'] = $this->getValueRequest('allocation', $paramAllocation, Sss_Ultility_SessionName::HARDWARE_SESSION);
		//get hardware list
		$list = $hardwareTable->getListHardware(-1, 0, $filterParam);
		//get hardware shepherd instance
		if (!empty($intanceId)) {
			$list = $hardwareTable->getListHardwareOfShepherd($intanceId, -1, 0, $filterParam);
		}
		$rowAll = $list->list;
		$pagination = $list->pagination;
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW, $rowAll);
		$this->view->assign(Sss_Ultility_CommonViewParamater::PAGINATION, $pagination);
		$count = ((($pagination->pagecurrent * Sss_Ultility_Setting::PAGE_SIZE) - Sss_Ultility_Setting::PAGE_SIZE));
		$columnNames = array(
			Resources::_('ID'),
			Resources::_('NAME'),
			Resources::_('OWNER'),
			Resources::_('TYPE'),
			Resources::_('VENDOR'),
			Resources::_('SERIAL'),
			Resources::_('LOCATION'),
			Resources::_('NOTES'),
			Resources::_('ALLOCATION')
		);
		$arrData = array();
		$index = 0;
		foreach ((array) $rowAll as $row) {
			$count++;
			$arrData[$index][] = $count;
			$arrData[$index][] = $row['hardwarename'];
			$arrData[$index][] = $row['owner'];
			$arrData[$index][] = $row['typename'];
			$arrData[$index][] = $row['vendorname'];
			$arrData[$index][] = "'".$row['serial_number'];
			$arrData[$index][] = $row['stocklocationname'];
			$arrData[$index][] = $row['note'];
			$arrData[$index][] = $row['allocation'];
			$index++;
		}

		if (isset($_GET['export']))
			$this->exportDataToExcel($columnNames, $arrData, Resources::_('HARDWARE'));
	}

	public function hardwareDetailAction()
	{
		$hardwareTable = new Application_Model_Mapper_Hardware();
		$systemTypeTable = new Application_Model_Mapper_SystemType();
		$vendorTable = new Application_Model_Mapper_Vendor();
		$documentTable = new Application_Model_Mapper_Document();
		$linkTable = new Application_Model_Mapper_Link();
		$historyTable = new Application_Model_Mapper_History();
		$historyContructor = new Application_Model_History();
		$params = $this->getRequest()->getPost();
		$hardwareId = $this->getRequest()->getParam('hardwareid', -1); //get hardwareid
		if (($hardwareId == -1 || (int) $hardwareId == 0) && isset($params['hardwareid']))
			$hardwareId = $params['hardwareid'];
		$this->view->assign('hardwareid', $hardwareId);
		//get hardware type
		$hardwareTypes = $systemTypeTable->getSystemBySystemName(Sss_Ultility_SystemName::HARDWARETYPE);
		$this->view->assign(Sss_Ultility_CommonViewParamater::HARDWATE_TYPES, $hardwareTypes);
		//get hardware status
		$hardwareStatus = $systemTypeTable->getSystemBySystemName(Sss_Ultility_SystemName::STATUS);
		$this->view->assign(Sss_Ultility_CommonViewParamater::HARDWATE_STATUS, $hardwareStatus);
		//get vendor
		$vendor = $vendorTable->getList();
		$this->view->assign(Sss_Ultility_CommonViewParamater::VENDOR, $vendor);
		$documents = $documentTable->getList($hardwareId); //get document list
		$this->view->assign(Sss_Ultility_CommonViewParamater::DOCUMENT, $documents);
		$tickets = $linkTable->getList($hardwareId); //get ticket list
		$this->view->assign(Sss_Ultility_CommonViewParamater::LINK, $tickets);
		$hardware = $hardwareTable->getHardwareById($hardwareId); //get hardware list         
		$this->view->assign(Sss_Ultility_CommonViewParamater::HARDWARE, $hardware);
		$history = $historyTable->getList($hardwareId, Sss_Ultility_Setting::HISTORY_TYPE_HARDWARE); //get history list  
		$this->view->assign(Sss_Ultility_CommonViewParamater::HISTORY, $history);
		$historyTypes = $systemTypeTable->getSystemBySystemName(Sss_Ultility_SystemName::HISTORYTYPE); //get history type
		$this->view->assign(Sss_Ultility_CommonViewParamater::HISTORYTPYE, $historyTypes);
		//set action and query string
		$strAction = 'hardware-detail';
		$queryString = '?' . 'hardwareid' . "=" . $hardwareId;
		$filePath = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FILEPATH, -1);
		if ($filePath != -1) {
			Sss_Ultility_Common::downloadFile($filePath);
			$this->redirect($this->view->url(array(
						Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
						Sss_Ultility_CommonViewParamater::ACTION => $this->view->actionName
					)) . $queryString);
		}
		if (isset($params[Sss_Ultility_CommonViewParamater::BTN_SAVE])) {
			$userInformation = Ovis_Controller::getLoggedUser();
			if ($userInformation) {
				$createBy = $userInformation['accountid'];
				// Process add history
				$historyContructor->setHistoryType( Sss_Ultility_Setting::HISTORY_TYPE_HARDWARE);
				$historyContructor->setModifiedDate(Sss_Ultility_Common::getDateTimeNumber());
				$historyContructor->setCreatedBy($createBy);
				$historyContructor->setHardware($hardwareId);
				$historyContructor->setNote($params['note']);
				$id = $historyTable->save($historyContructor);
				if (isset($id)) {
					$this->redirect(Resources::_('ADD_HISTORY_SUCCESSFULL'), $this->view->url(array(
								Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
								Sss_Ultility_CommonViewParamater::ACTION => $strAction
							)) . $queryString);
				} else {
					$this->redirect(Resources::_('ADD_HISTORY_FAILED'), $this->view->url(array(
								Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
								Sss_Ultility_CommonViewParamater::ACTION => $strAction
							)) . $queryString);
				}
			}
		}
		$actionName = 'hardware';
		$hardwareTitle = Resources::_('HARDWARE');
		$harhwareDetailTitle = Resources::_('HARDWARE_DETAIL');
		$h = $this->getRequest()->getParam('h', -1);
		if ($hardware->status == 29 && $h == -1) {
			$actionName = 'rma';
			$hardwareTitle = Resources::_('RMA');
			$harhwareDetailTitle = Resources::_('RMA_DETAIL');
		}
		//action button
		$actionbuttons = array(
			new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::PRINTF, 'hardware-detail-export?print=1&' . "hardwareid=$hardwareId", Resources::_('PRINT')),
			new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::BACK, $actionName, Resources::_('BTN_BACK'))
		);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ACTION_BUTTONS, $actionbuttons);
		//get breadscrumb
		$breadscrumbs = array(
			new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
			new Sss_CommonEntity_BreadScrumb($hardwareTitle, $actionName),
			new Sss_CommonEntity_BreadScrumb($harhwareDetailTitle, '#')
		);
		$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
	}

	public function hardwareDetailExportAction()
	{
		$hardwareTable = new Application_Model_Mapper_Hardware();
		$systemTypeTable = new Application_Model_Mapper_SystemType();
		$vendorTable = new Application_Model_Mapper_Vendor();
		$documentTable = new Application_Model_Mapper_Document();
		$linkTable = new Application_Model_Mapper_Link();
		$historyTable = new Application_Model_Mapper_History();
		//get hardwareid
		$params = $this->getRequest()->getPost();

		$hardwareId = $this->getRequest()->getParam('hardwareid', -1);
		$flag = $this->getRequest()->getParam('flag',1);
		$this->view->assign('flag', $flag);
		if (($hardwareId == -1 || (int) $hardwareId == 0) && isset($params['hardwareid']))
			$hardwareId = $params['hardwareid'];
		$this->view->assign('hardwareid', $hardwareId);

		//get hardware type
		$hardwareTypes = $systemTypeTable->getSystemBySystemName(Sss_Ultility_SystemName::HARDWARETYPE);
		$this->view->assign(Sss_Ultility_CommonViewParamater::HARDWATE_TYPES, $hardwareTypes);

		//get hardware status
		$hardwareStatus = $systemTypeTable->getSystemBySystemName(Sss_Ultility_SystemName::STATUS);
		$this->view->assign(Sss_Ultility_CommonViewParamater::HARDWATE_STATUS, $hardwareStatus);

		//get vendor
		$vendor = $vendorTable->getList();
		$this->view->assign(Sss_Ultility_CommonViewParamater::VENDOR, $vendor);

		//get document list
		$documents = $documentTable->getList($hardwareId);
		$this->view->assign(Sss_Ultility_CommonViewParamater::DOCUMENT, $documents);

		//get ticket list
		$tickets = $linkTable->getList($hardwareId);
		$this->view->assign(Sss_Ultility_CommonViewParamater::LINK, $tickets);

		//get hardware list
		$hardware = $hardwareTable->getHardwareById($hardwareId);
		$this->view->assign(Sss_Ultility_CommonViewParamater::HARDWARE, $hardware);

		//get history list
		$history = $historyTable->getList($hardwareId);
		$this->view->assign(Sss_Ultility_CommonViewParamater::HISTORY, $history);

		//get history type
		$historyTypes = $systemTypeTable->getSystemBySystemName(Sss_Ultility_SystemName::HISTORYTYPE);
		$this->view->assign(Sss_Ultility_CommonViewParamater::HISTORYTPYE, $historyTypes);

		$queryString = '?hardwareid=' . $hardwareId;

		$this->view->assign(Sss_Ultility_CommonViewParamater::ACTION_COMMON, 'hardware-detail');
		$this->view->assign(Sss_Ultility_CommonViewParamater::QUERY_STRING, $queryString);
	}

	public function hardwareManualAction()
	{
		$documentTable = new Application_Model_Mapper_Document();
		$documentContructor = new Application_Model_Document();
		$referenceTable = new Application_Model_Mapper_References();
		$referenceContructor = new Application_Model_References();
		//get hardwareid
		$params = $this->getRequest()->getPost();
		$hardwareId = $this->getRequest()->getParam('hardwareid', -1);
		if (($hardwareId == -1 || (int) $hardwareId == 0) && isset($params['hardwareid']))
			$hardwareId = $params['hardwareid'];
		$this->view->assign('hardwareid', $hardwareId);
		$documentId = $this->getRequest()->getParam('documentid', -1);
		if (($documentId == -1 || (int) $documentId == 0) && isset($params['documentid']))
			$documentId = $params['documentid'];
		$this->view->assign('documentid', $documentId);
		$strAction = 'hardware-manual';
		$queryString = '?' . 'hardwareid' . "=" . $hardwareId . '&popup=1';
		$this->view->assign(Sss_Ultility_CommonViewParamater::QUERY_STRING, $queryString);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ACTION, $strAction);
		//get document edit
		$document = $documentTable->getDocumentById($documentId);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW_DETAIL, $document);
		$actionName = Resources::_('ADD_DOCUMENT');
		$userInformation = Ovis_Controller::getLoggedUser();
		//delete document
		$deleteDocumentId = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::DELETE_DOCUMENT_ID, -1);
		if ($userInformation && isset($deleteDocumentId) && $deleteDocumentId != -1) {
			$documentDelete = $documentTable->getDocumentById($deleteDocumentId);
			if ($documentDelete->path && file_exists(getcwd() . $documentDelete->path)) {
				unlink(getcwd() . $documentDelete->path);
			}
			$deleteId = $documentTable->deleteRow((int) $deleteDocumentId);
			$deleteId = $referenceTable->deleteRow( (int) $deleteDocumentId);
			$mesage = isset($deleteId) ? Resources::_('DELETE_DOCUMENT_SUCCESSFULL') : Resources::_('DELETE_DOCUMENT_FAIL');
			$this->view->assign(Sss_Ultility_CommonViewParamater::NOTICEMSG, $mesage);
		}
		//get document list
		$documentList = $documentTable->getList(null, Sss_Ultility_Setting::DOCUMENT_HARDWARE, null, null, null, 1, $hardwareId);
		$documentList = ($hardwareId == -1) ? $documentTable->getList(null, Sss_Ultility_Setting::DOCUMENT_HARDWARE, null, 1, 1) : $documentList;
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW, $documentList);
		if ($userInformation && isset($params[Sss_Ultility_CommonViewParamater::BTN_SAVE])) {
			//upload document
			$fullPath = null;
			$fileName = $_FILES[Sss_Ultility_CommonViewParamater::FILE_UPLOAD][Sss_Ultility_CommonViewParamater::NAME];
			if ($fileName) {
				$filePath = $_FILES[Sss_Ultility_CommonViewParamater::FILE_UPLOAD][Sss_Ultility_CommonViewParamater::TMP_NAME];
				$newPath = Sss_Ultility_CommonViewParamater::FILE_PATH_DOCUMENT . $fileName;
				move_uploaded_file($filePath, $newPath);
				$fullPath = '/' . Sss_Ultility_CommonViewParamater::FILE_PATH_DOCUMENT . $fileName;
			}
			$createBy = $userInformation['accountid'];
			// Process add/edit new document
			$documentContructor->setDocumentName($params['documentname']);
			$documentContructor->setCreatedDate(Sss_Ultility_Common::getDateTimeNumber());
			$documentContructor->setUpdatedDate(Sss_Ultility_Common::getDateTimeNumber());
			$documentContructor->setCreatedBy($createBy);
			$documentContructor->setUpdatedBy($createBy);
			$documentContructor->setDestination($hardwareId);
			$documentContructor->setDocumentType(Sss_Ultility_Setting::DOCUMENT_HARDWARE);
			$documentContructor->setPath($fullPath);
			$documentContructor->setIsused(1);
			$documentContructor->setVendor($params['vendor']);
			$id = $documentTable->save($documentContructor);
			if (isset($id)) {
				if ($hardwareId != -1) {
					$referenceContructor->setReferenceType(Sss_Ultility_Setting::DOCUMENT_HARDWARE);
					$referenceContructor->setDocument($id);
					$referenceContructor->setDestination($hardwareId);
					$checkReference = $referenceTable->checkReference($hardwareId, $documentId, Sss_Ultility_Setting::DOCUMENT_HARDWARE);
					$checkReference == false ? $referenceTable->save($referenceContructor) : null;
				}
				$this->redirect(Resources::_('ADD_DOCUMENT_SUCCESSFULL'), $this->view->url(array(
							Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
							Sss_Ultility_CommonViewParamater::ACTION => $strAction
						)) . $queryString);
				return;
			} else {
				$this->redirect(Resources::_('ADD_DOCUMENT_FAIL'), $this->view->url(array(
							Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
							Sss_Ultility_CommonViewParamater::ACTION => $strAction
						)) . $queryString);
				return;
			}
		}
		//get breadscrumb
		$breadscrumbs = array(
			new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
			new Sss_CommonEntity_BreadScrumb(Resources::_('HARDWARE'), '#'),
			new Sss_CommonEntity_BreadScrumb(Resources::_('DOCUMENT'), '#'),
			new Sss_CommonEntity_BreadScrumb($actionName, '#')
		);
		$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
	}

	public function hardwareTicketAction()
	{
		$linkTable = new Application_Model_Mapper_Link();
		$linkContructor = new Application_Model_Link();
		//get hardwareid
		$params = $this->getRequest()->getPost();
		$hardwareId = $this->getRequest()->getParam('hardwareid', -1);
		if (($hardwareId == -1 || (int) $hardwareId == 0) && isset($params['hardwareid']))
			$hardwareId = $params['hardwareid'];
		$this->view->assign('hardwareid', $hardwareId);

		$linkId = $this->getRequest()->getParam('linkid', -1);
		if (($linkId == -1 || (int) $linkId == 0) && isset($params['linkid']))
			$linkId = $params['linkid'];
		$this->view->assign('linkid', $linkId);


		$strAction = 'hardware-ticket';
		$queryString = '?' . 'hardwareid' . "=" . $hardwareId . '&popup=1';
		$this->view->assign(Sss_Ultility_CommonViewParamater::QUERY_STRING, $queryString);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ACTION, $strAction);

		//get link edit
		$link = $linkTable->getById($linkId);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW_DETAIL, $link);

		$actionName = Resources::_('ADD_OTRS_TICKET');

		$userInformation = Ovis_Controller::getLoggedUser();
		if ($userInformation) {
			//delete ticket
			$deleteLinkId = $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::DELETE_LINK_ID, -1);
			if (isset($deleteLinkId) && $deleteLinkId != -1) {
				$deleteId = $linkTable->deleteRow((int) $deleteLinkId);
				if (isset($deleteId)) {
					$this->view->assign(Sss_Ultility_CommonViewParamater::NOTICEMSG, Resources::_('DELETE_LINK_SUCCESSFULL'));
				} else {
					$this->view->assign(Sss_Ultility_CommonViewParamater::NOTICEMSG, Resources::_('DELETE_LINK_FAIL'));
				}
			}
		}

		//get link list
		$linkList = $linkTable->getList($hardwareId, null);
		if ($hardwareId == -1) {
			$linkList = $linkTable->getList(-1, null);
		}
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW, $linkList);

		// save ticket
		if (isset($params[Sss_Ultility_CommonViewParamater::BTN_SAVE])) {
			if ($userInformation) {
				$createBy = $userInformation['accountid'];
				// Process add ticket
				$linkContructor->setLinkName($params['linkname']);
				$linkContructor->setCreatedDate(Sss_Ultility_Common::getDateTimeNumber());
				$linkContructor->setCreatedBy($createBy);
				$linkContructor->setHardware($hardwareId);
				$linkContructor->setIsused(1);
				$linkContructor->setUrl($params['url']);
				$id = $linkTable->save($linkContructor);

				if (isset($id)) {
					$this->redirect(Resources::_('ADD_TICKET_SUCCESSFULL'), $this->view->url(array(
								Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
								Sss_Ultility_CommonViewParamater::ACTION => $strAction
							)) . $queryString);
					return;
				} else {
					$this->redirect(Resources::_('ADD_TICKET_FAIL'), $this->view->url(array(
								Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
								Sss_Ultility_CommonViewParamater::ACTION => $strAction
							)) . $queryString);
					return;
				}
			}
		}

		//get breadscrumb
		$breadscrumbs = array(
			new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
			new Sss_CommonEntity_BreadScrumb(Resources::_('HARDWARE'), '#'),
			new Sss_CommonEntity_BreadScrumb(Resources::_('OTRS_TICKETS'), '#'),
			new Sss_CommonEntity_BreadScrumb($actionName, '#')
		);
		$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
	}

	public function stockLocationSearchAction()
	{
		$stocklocationsTable = Sss_Service_Locator::getInstance()->getService($this->_getOvisTable('StockLocation'));

		//get order, page, limit param
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD] = $this->getValueRequest(Sss_Ultility_CommonViewParamater::ORDERFIELD, $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::ORDERFIELD, Sss_Ultility_CommonViewParamater::UNDERFINE), Sss_Ultility_SessionName::SHIPMENT_STOCKLOCATION_SEARCH_SESSION);
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE] = $this->getValueRequest(Sss_Ultility_CommonViewParamater::ORDERTYPE, $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::ORDERTYPE, Sss_Ultility_CommonViewParamater::UNDERFINE), Sss_Ultility_SessionName::SHIPMENT_STOCKLOCATION_SEARCH_SESSION);
		$filterParam[Sss_Ultility_CommonViewParamater::PAGE] = $this->getValueRequest(Sss_Ultility_CommonViewParamater::PAGE, $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::PAGE, Sss_Ultility_CommonViewParamater::UNDERFINE), Sss_Ultility_SessionName::SHIPMENT_STOCKLOCATION_SEARCH_SESSION);

		$limit = $this->getValueRequest(Sss_Ultility_CommonViewParamater::LIMIT, $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::LIMIT, Sss_Ultility_CommonViewParamater::UNDERFINE), Sss_Ultility_SessionName::SHIPMENT_STOCKLOCATION_SEARCH_SESSION);

		//test param filter: omit title text in field
		$paramName = strcmp($this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'stocklocationname', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('STOCK_LOCATION_NAME')) == 0 ? '' : $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'stocklocationname', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$paramContact = strcmp($this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'contact', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('STOCK_LOCATION_CONTACT')) == 0 ? '' : $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'contact', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$paramType = strcmp($this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'stocklocationtype', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('STOCK_LOCATION_TYPE')) == 0 ? '' : $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::FIX . 'stocklocationtype', Sss_Ultility_CommonViewParamater::UNDERFINE);


		$page = $filterParam[Sss_Ultility_CommonViewParamater::PAGE];

		$filterParam['stocklocationname'] = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'stocklocationname', trim($paramName), Sss_Ultility_SessionName::SHIPMENT_STOCKLOCATION_SEARCH_SESSION);
		$filterParam['contact'] = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'contact', trim($paramContact), Sss_Ultility_SessionName::SHIPMENT_STOCKLOCATION_SEARCH_SESSION);
		$filterParam['stocklocationtype'] = $this->getValueRequest(Sss_Ultility_CommonViewParamater::FIX . 'stocklocationtype', trim($paramType), Sss_Ultility_SessionName::SHIPMENT_STOCKLOCATION_SEARCH_SESSION);


		$limit = $this->getValueRequest(Sss_Ultility_CommonViewParamater::LIMIT, $this->getRequest()->getParam(Sss_Ultility_CommonViewParamater::LIMIT, Sss_Ultility_CommonViewParamater::UNDERFINE), Sss_Ultility_SessionName::SHIPMENT_STOCKLOCATION_SEARCH_SESSION);

		$stockLocationId = $this->getRequest()->getParam('stocklocationid', -1);
		//$this->view->assign(Sss_Ultility_CommonViewParamater::PAGINATION, $pagination);
		//get Stock locations list                        
		$list = $stocklocationsTable->getList($limit, 0, $filterParam, $stockLocationId);
		$row = $list->list;
		$pagination = $list->pagination;
		$this->view->assign(Sss_Ultility_CommonViewParamater::FILTER_PARAM, $filterParam);
		$this->view->assign(Sss_Ultility_CommonViewParamater::LIMIT, $limit);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW, $row);
		$this->view->assign(Sss_Ultility_CommonViewParamater::PAGINATION, $pagination);
	}

	public function rmaAction()
	{
		$userInformation = Ovis_Controller::getLoggedUser();
		$hardwareTable = new Application_Model_Mapper_Hardware();
		$linkTable = new Application_Model_Mapper_Link();
		$systemTypeTable = new Application_Model_Mapper_SystemType();
		$get = $this->getRequest()->getParams();
		$isSearch = isset($get['s']) && $get['s'] == 1;
		
		//get order, page, limit param
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD] = isset($get[Sss_Ultility_CommonViewParamater::ORDERFIELD]) ? $get[Sss_Ultility_CommonViewParamater::ORDERFIELD] : null;
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE] = isset($get[Sss_Ultility_CommonViewParamater::ORDERTYPE]) ? $get[Sss_Ultility_CommonViewParamater::ORDERTYPE] : null;
		$filterParam[Sss_Ultility_CommonViewParamater::PAGE] = isset($get[Sss_Ultility_CommonViewParamater::PAGE]) ? $get[Sss_Ultility_CommonViewParamater::PAGE] : 1;

		//test param filter: omit title text in field
		$paramName = $isSearch ? strcmp($this->getRequest()->getParam('hardwarename', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('DIVICE')) == 0 ? '' : $this->getRequest()->getParam('hardwarename', Sss_Ultility_CommonViewParamater::UNDERFINE)  : '';

		$paramOwner = $isSearch ? strcmp($this->getRequest()->getParam('owner', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('OWNER')) == 0 ? '' : $this->getRequest()->getParam('owner', Sss_Ultility_CommonViewParamater::UNDERFINE)  : '';

		$paramVendor = $isSearch ? strcmp($this->getRequest()->getParam('vendorname', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('VENDOR')) == 0 ? '' : $this->getRequest()->getParam('vendorname', Sss_Ultility_CommonViewParamater::UNDERFINE)  : '';

		$paramSerial = $isSearch ? strcmp($this->getRequest()->getParam('serial_number', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('SERIAL#')) == 0 ? '' : $this->getRequest()->getParam('serial_number', Sss_Ultility_CommonViewParamater::UNDERFINE)  : '';

		$paramDate = $isSearch ? strcmp($this->getRequest()->getParam('created_date', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('DATE')) == 0 ? '' : $this->getRequest()->getParam('created_date', Sss_Ultility_CommonViewParamater::UNDERFINE)  : '';

		$paramStatus = $isSearch ? strcmp($this->getRequest()->getParam('rma_status', Sss_Ultility_CommonViewParamater::UNDERFINE), '') == 0 ? '' : $this->getRequest()->getParam('rma_status', Sss_Ultility_CommonViewParamater::UNDERFINE)  : '';

		$paramAllocation = $isSearch ? strcmp($this->getRequest()->getParam('allocation', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('ALLOCATION')) == 0 ? '' : $this->getRequest()->getParam('allocation', Sss_Ultility_CommonViewParamater::UNDERFINE)  : '';

		//get harware filter
		$filterParam['hardwarename'] = $this->getValueRequest('hardwarename', trim($paramName), Sss_Ultility_SessionName::OVIS_RMA_SESSION);

		$filterParam['owner'] = $this->getValueRequest('owner', trim($paramOwner), Sss_Ultility_SessionName::OVIS_RMA_SESSION);

		$filterParam['vendorname'] = $this->getValueRequest('vendorname', trim($paramVendor), Sss_Ultility_SessionName::OVIS_RMA_SESSION);

		$filterParam['serial_number'] = $this->getValueRequest('serial_number', trim($paramSerial), Sss_Ultility_SessionName::RMA_SESSION);

		$filterParam['created_date'] = $this->getValueRequest('created_date', $paramDate, Sss_Ultility_SessionName::OVIS_RMA_SESSION);

		$filterParam['rma_status'] = $this->getValueRequest('rma_status', $paramStatus, Sss_Ultility_SessionName::OVIS_RMA_SESSION);

		$filterParam['allocation'] = $this->getValueRequest('allocation', $paramAllocation, Sss_Ultility_SessionName::OVIS_RMA_SESSION);

		//get status rma
		$rmaStatus = $systemTypeTable->getSystemBySystemName(Sss_Ultility_SystemName::RMASTATUS);
		$this->view->assign(Sss_Ultility_CommonViewParamater::RMA_STATUS, $rmaStatus);

		//get ticket list
		$tickets = $linkTable->getList(null);
		$this->view->assign(Sss_Ultility_CommonViewParamater::LINK, $tickets);

		//get hardware list
		$list = $hardwareTable->getListRMAHardware($this->view->limit, 0, $filterParam, $userInformation['accounttype'] != Sss_Ultility_Setting::ACCOUNT_OVIS ? $userInformation['accountid'] : null);
		$row = $list->list;
		$pagination = $list->pagination;
		$this->view->assign(Sss_Ultility_CommonViewParamater::FILTER_PARAM, $filterParam);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW, $row);
		$this->view->assign(Sss_Ultility_CommonViewParamater::PAGINATION, $pagination);
		$orderQueryString = '';
		if ($isSearch) {
			$orderQueryString = '&' . Sss_Ultility_CommonViewParamater::PAGE . '=' . $filterParam[Sss_Ultility_CommonViewParamater::PAGE] . '&s=1';
		} else {
			$orderQueryString = '&' . Sss_Ultility_CommonViewParamater::PAGE . '=' . $filterParam[Sss_Ultility_CommonViewParamater::PAGE];
		}
		$queryString = '';
		if ($isSearch) {
			$queryString .= '&s=1';
		}
		if (!is_null($filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD])) {
			$queryString .= '&' . Sss_Ultility_CommonViewParamater::ORDERFIELD . '=' . $filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD];
		}
		if (!is_null($filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE])) {
			$queryString .= '&' . Sss_Ultility_CommonViewParamater::ORDERTYPE . '=' . $filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE];
		}
		$this->view->assign(Sss_Ultility_CommonViewParamater::QUERY_STRING, $queryString);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ORDER_QUERY_STRING, $orderQueryString);
		//action button
		$this->view->assign(Sss_Ultility_CommonViewParamater::OTHER_QUERY_STRING, "?status=" . Sss_Ultility_Setting::RMA);
		$this->view->assign(Sss_Ultility_CommonViewParamater::OTHER_CONTROLLER_NAME, Sss_Ultility_CommonViewParamater::INVENTORY);

		$actionbuttons = array(
			new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::EXPORT, 'rma-export?export=1', Resources::_('EXPORT')),
			new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::PRINTF, 'rma-export?print=1', Resources::_('PRINT')),
			new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::SEARCH, 'javascript:hideShow(this);', Resources::_('SEARCH'))
		);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ACTION_BUTTONS, $actionbuttons);
		//get breadscrumb
		$breadscrumbs = array(
			new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
			new Sss_CommonEntity_BreadScrumb(Resources::_('RMA'), '#')
		);
		$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
	}

	public function rmaExportAction()
	{
		$excel = new PHPExcel();
		$excel->setActiveSheetIndex(0);


		$hardwareTable = new Application_Model_Mapper_Hardware();
		$linkTable = new Application_Model_Mapper_Link();

		//get order, page, limit param
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERFIELD] = isset($get[Sss_Ultility_CommonViewParamater::ORDERFIELD]) ? $get[Sss_Ultility_CommonViewParamater::ORDERFIELD] : null;
		$filterParam[Sss_Ultility_CommonViewParamater::ORDERTYPE] = isset($get[Sss_Ultility_CommonViewParamater::ORDERTYPE]) ? $get[Sss_Ultility_CommonViewParamater::ORDERTYPE] : null;
		$filterParam[Sss_Ultility_CommonViewParamater::PAGE] = isset($get[Sss_Ultility_CommonViewParamater::PAGE]) ? $get[Sss_Ultility_CommonViewParamater::PAGE] : 1;

		//test param filter: omit title text in field
		$paramName = strcmp($this->getRequest()->getParam('hardwarename', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('DIVICE')) == 0 ? '' : $this->getRequest()->getParam('hardwarename', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$paramOwner = strcmp($this->getRequest()->getParam('owner', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('OWNER')) == 0 ? '' : $this->getRequest()->getParam('owner', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$paramVendor = strcmp($this->getRequest()->getParam('vendorname', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('VENDOR')) == 0 ? '' : $this->getRequest()->getParam('vendorname', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$paramSerial = strcmp($this->getRequest()->getParam('serial_number', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('SERIAL#')) == 0 ? '' : $this->getRequest()->getParam('serial_number', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$paramDate = strcmp($this->getRequest()->getParam('created_date', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('DATE')) == 0 ? '' : $this->getRequest()->getParam('created_date', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$paramStatus = strcmp($this->getRequest()->getParam('rma_status', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('STATUS')) == 0 ? '' : $this->getRequest()->getParam('rma_status', Sss_Ultility_CommonViewParamater::UNDERFINE);
		$paramAllocation = strcmp($this->getRequest()->getParam('allocation', Sss_Ultility_CommonViewParamater::UNDERFINE), Resources::_('ALLOCATION')) == 0 ? '' : $this->getRequest()->getParam('allocation', Sss_Ultility_CommonViewParamater::UNDERFINE);

		//get harware filter
		$filterParam['hardwarename'] = $this->getValueRequest('hardwarename', $paramName, Sss_Ultility_SessionName::RMA_SESSION);
		$filterParam['owner'] = $this->getValueRequest('owner', $paramOwner, Sss_Ultility_SessionName::RMA_SESSION);
		$filterParam['vendorname'] = $this->getValueRequest('vendorname', $paramVendor, Sss_Ultility_SessionName::RMA_SESSION);
		$filterParam['serial_number'] = $this->getValueRequest('serial_number', $paramSerial, Sss_Ultility_SessionName::RMA_SESSION);
		$filterParam['created_date'] = $this->getValueRequest('created_date', $paramDate, Sss_Ultility_SessionName::HARDWARE_SESSION);
		$filterParam['rma_status'] = $this->getValueRequest('rma_status', $paramStatus, Sss_Ultility_SessionName::RMA_SESSION);
		$filterParam['allocation'] = $this->getValueRequest('allocation', $paramAllocation, Sss_Ultility_SessionName::RMA_SESSION);

		//get ticket list
		$tickets = $linkTable->getList(null);

		//get hardware list
		$list = $hardwareTable->getListRMAHardware(-1, 0, $filterParam);
		$rowAll = $list->list;
		$pagination = $list->pagination;
		$this->view->assign(Sss_Ultility_CommonViewParamater::ROW, $rowAll);
		$this->view->assign(Sss_Ultility_CommonViewParamater::PAGINATION, $pagination);
		$count = ((($pagination->pagecurrent * Sss_Ultility_Setting::PAGE_SIZE) - Sss_Ultility_Setting::PAGE_SIZE));
		$columnNames = array(
			Resources::_('ID'),
			Resources::_('CUSTOMER'),
			Resources::_('DIVICE'),
			Resources::_('SERIAL#'),
			Resources::_('VENDOR'),
			Resources::_('DATE'),
			Resources::_('TYPE'),
			Resources::_('OTRS_TICKET')
		);

		$arrData = array();
		$index = 0;
		foreach ((array) $rowAll as $row) {
			$count++;
			$arrData[$index][] = $count;
			$arrData[$index][] = $row['owner'];
			$arrData[$index][] = $row['hardwarename'];
			$arrData[$index][] = $row['serial_number'];
			$arrData[$index][] = $row['vendorname'];
			$arrData[$index][] = gmdate(DATEFORMAT, $row['created_date']);
			$arrData[$index][] = $row['typename'];
			foreach ($tickets as $lnk) {
				if ($row['hardwareid'] == $lnk['hardware']) {
					$arrLinks[] = $lnk['linkname'];
				}
			}
			$arrData[$index][] = implode(',', $arrLinks);
			unset($arrLinks);
			$index++;
		}
		if (isset($_GET['export']))
			$this->exportDataToExcel($columnNames, $arrData, Resources::_('RMA'));
	}

	public function rmaDetailAction()
	{
		$userInformation = Ovis_Controller::getLoggedUser();
		if ($userInformation['accounttype'] != Sss_Ultility_Setting::ACCOUNT_OVIS) {
			$this->_redirect('/user/login');
		}
		$hardwareTable = new Application_Model_Mapper_Hardware();
		$linkTable = new Application_Model_Mapper_Link();
		$systemTypeTable = new Application_Model_Mapper_SystemType();
		$historyTable = new Application_Model_Mapper_History();
		$historyContructor = new Application_Model_History();
		$params = $this->getRequest()->getPost();
		$rmaStatus = $systemTypeTable->getSystemBySystemName(Sss_Ultility_SystemName::RMASTATUS);//get status rma
		$this->view->assign(Sss_Ultility_CommonViewParamater::RMA_STATUS, $rmaStatus);
		$rmaType = $systemTypeTable->getSystemBySystemName(Sss_Ultility_SystemName::RMATYPE);//get type rma
		$this->view->assign(Sss_Ultility_CommonViewParamater::RMA_TYPE, $rmaType);
		$hardwareId = $this->getRequest()->getParam('hardwareid', -1);//get hardware id
		if (($hardwareId == -1 || (int) $hardwareId == 0) && isset($params['hardwareid']))
			$hardwareId = $params['hardwareid'];
		$this->view->assign('hardwareid', $hardwareId);
		$hardware = $hardwareTable->getHardwareById($hardwareId);//get hardware list       
		$this->view->assign(Sss_Ultility_CommonViewParamater::HARDWARE, $hardware);
		$tickets = $linkTable->getList($hardwareId);//get ticket list
		$this->view->assign(Sss_Ultility_CommonViewParamater::LINK, $tickets);
		$history = $historyTable->getList($hardwareId, Sss_Ultility_Setting::HISTORY_TYPE_RMA);//get history list  
		$this->view->assign(Sss_Ultility_CommonViewParamater::HISTORY, $history);
		$historyTypes = $systemTypeTable->getSystemBySystemName(Sss_Ultility_SystemName::HISTORYTYPE);//get history type
		$this->view->assign(Sss_Ultility_CommonViewParamater::HISTORYTPYE, $historyTypes);
		//set action and query string
		$strAction = 'rma-detail';
		$queryString = '?' . 'hardwareid' . "=" . $hardwareId;
		if ($userInformation && isset($params[Sss_Ultility_CommonViewParamater::BTN_SAVE])) {
			$createBy = $userInformation['accountid'];
			$data = Sss_Ultility_InventoryFuction:: arrData($createBy,$hardwareId,$params);
			$id = $historyTable->save($data);
			$message = isset($id) ? Resources::_('ADD_HISTORY_SUCCESSFULL') : Resources::_('ADD_HISTORY_FAILED');
			$this->redirect($message, $this->view->url(array(
						Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
						Sss_Ultility_CommonViewParamater::ACTION => $strAction
					)) . $queryString);
		}
		//update rma
		if ($userInformation && isset($params['btnUpdate'])) {
			$createBy = $userInformation['accountid'];
			if ($hardware->rma_status != $params['rma_status']) {
				$statusNewName = $systemTypeTable->getById($params['rma_status'])->typename;
				$note = Resources::_('RMA_TYPE') . ' ' . Resources::_('FROM_HISTORY') . " '" . $hardware->rma_status_name . "' " . Resources::_('TO_HISTORY') . " '" . $statusNewName . "'";
				$historyContructor->setHistoryType(Sss_Ultility_Setting::HISTORY_TYPE_RMA);
				$historyContructor->setModifiedDate(Sss_Ultility_Common::getDateTimeNumber());
				$historyContructor->setCreatedBy($createBy);
				$historyContructor->setHardware($hardwareId);
				$historyContructor->setNote($note);
				$id = $historyTable->save($historyContructor);
			}
			if ($hardware->rma_type != $params['rma_type']) {
				$typeNewName = $systemTypeTable->getById($params['rma_type'])->typename;
				$note = Resources::_('SERIAL_NUMBER') . ' ' . Resources::_('FROM_HISTORY') . " '" . $hardware->rma_type_name . "' " . Resources::_('TO_HISTORY') . " '" . $typeNewName . "'";
				$historyContructor->setHistoryType(Sss_Ultility_Setting::HISTORY_TYPE_RMA);
				$historyContructor->setModifiedDate(Sss_Ultility_Common::getDateTimeNumber());
				$historyContructor->setCreatedBy($createBy);
				$historyContructor->setHardware($hardwareId);
				$historyContructor->setNote($note);
				$id = $historyTable->save($historyContructor);
			}

			$status = $params['rma_status'] == Sss_Ultility_Setting::RMA_STATUS_CLOSED ? Sss_Ultility_Setting::STATUS_ACTIVE : Sss_Ultility_Setting::OVIS_RMA;
			$hardwareContructor = $hardwareTable->findById((int) $hardwareId);
			$hardwareContructor->setRmaType($params['rma_type']);
			$hardwareContructor->setRmaStatus($params['rma_status']);
			$hardwareContructor->setStatus($status);
			$Id = $hardwareTable->save($hardwareContructor);
			$params = null;
			$message = isset($Id) ? Resources::_('EDIT_RMA_SUCCESSFULL') : Resources::_('EDIT_RMA_FAILED');
			$this->redirect($message, $this->view->url(array(
						Sss_Ultility_CommonViewParamater::CONTROLLER => $this->view->controllerName,
						Sss_Ultility_CommonViewParamater::ACTION => 'rma'
					)) . $queryString);
			return;
		}
		//action button
		$actionbuttons = array(
			new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::PRINTF, 'rma-detail-export?print=1&' . "hardwareid=$hardwareId", Resources::_('PRINT')),
			new Sss_CommonEntity_ActionButton(Sss_Ultility_ActionButtonType::BACK, 'rma', Resources::_('BTN_BACK'))
		);
		$this->view->assign(Sss_Ultility_CommonViewParamater::ACTION_BUTTONS, $actionbuttons);
		//get breadscrumb        
		$breadscrumbs = array(
			new Sss_CommonEntity_BreadScrumb($this->_menuName, ''),
			new Sss_CommonEntity_BreadScrumb(Resources::_('RMA'), '#'),
			new Sss_CommonEntity_BreadScrumb(Resources::_('RMA_DETAIL'), '#')
		);
		$this->view->assign(Sss_Ultility_CommonViewParamater::BREADSCRUMBS, $breadscrumbs);
	}

	public function rmaDetailExportAction()
	{
		$hardwareTable = new Application_Model_Mapper_Hardware();
		$linkTable = new Application_Model_Mapper_Link();
		$systemTypeTable = new Application_Model_Mapper_SystemType();
		$historyTable = new Application_Model_Mapper_History();

		$params = $this->getRequest()->getPost();

		//get status rma
		$rmaStatus = $systemTypeTable->getSystemBySystemName(Sss_Ultility_SystemName::RMASTATUS);
		$this->view->assign(Sss_Ultility_CommonViewParamater::RMA_STATUS, $rmaStatus);

		//get type rma
		$rmaType = $systemTypeTable->getSystemBySystemName(Sss_Ultility_SystemName::RMATYPE);
		$this->view->assign(Sss_Ultility_CommonViewParamater::RMA_TYPE, $rmaType);

		//get hardware id
		$hardwareId = $this->getRequest()->getParam('hardwareid', -1);
		if (($hardwareId == -1 || (int) $hardwareId == 0) && isset($params['hardwareid']))
			$hardwareId = $params['hardwareid'];
		$this->view->assign('hardwareid', $hardwareId);

		//get hardware list
		$hardware = $hardwareTable->getHardwareById($hardwareId);
		$this->view->assign(Sss_Ultility_CommonViewParamater::HARDWARE, $hardware);

		//get ticket list
		$tickets = $linkTable->getList($hardwareId);
		$this->view->assign(Sss_Ultility_CommonViewParamater::LINK, $tickets);

		//get history list
		$history = $historyTable->getList($hardwareId, Sss_Ultility_Setting::HISTORY_TYPE_RMA);
		$this->view->assign(Sss_Ultility_CommonViewParamater::HISTORY, $history);

		//get history type
		$historyTypes = $systemTypeTable->getSystemBySystemName(Sss_Ultility_SystemName::HISTORYTYPE);
		$this->view->assign(Sss_Ultility_CommonViewParamater::HISTORYTPYE, $historyTypes);

		//set action and query string
		$queryString = "?hardwareid=" . $hardwareId;

		$this->view->assign(Sss_Ultility_CommonViewParamater::ACTION_COMMON, 'rma-detail');
		$this->view->assign(Sss_Ultility_CommonViewParamater::QUERY_STRING, $queryString);
	}
}